<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class DocumentType extends Model
{
    protected $table = 'document_types';
    
    protected $fillable = [
        'name', 'category', 'icon', 'color', 'is_active', 'sort_order'
    ];
    
    protected $casts = [
        'is_active' => 'boolean',
        'sort_order' => 'integer',
    ];
    
    public function documents(): HasMany
    {
        return $this->hasMany(Document::class);
    }
    
    public function getDocumentsCountAttribute(): int
    {
        return $this->documents()->count();
    }
    
    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }
    
    public function scopeCertificates($query)
    {
        return $query->where('category', 'certificate');
    }
    
    public function scopeInvoices($query)
    {
        return $query->where('category', 'invoice');
    }
    
    public function scopeLicenses($query)
    {
        return $query->where('category', 'license');
    }
}