<?php

namespace App\Models;

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

class FinancialYear extends Model
{
    protected $table = 'financial_years';
    
    protected $fillable = [
        'year_name', 'start_date', 'end_date', 'is_active'
    ];
    
    protected $casts = [
        'start_date' => 'date',
        'end_date' => 'date',
        'is_active' => 'boolean',
    ];
    
    public function documents()
{
    return $this->hasMany(Document::class, 'financial_year_id');
}
    
    public function getCurrentYearAttribute(): bool
    {
        $now = now();
        return $now->between($this->start_date, $this->end_date);
    }
    
    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }
}