<?php

namespace App\Models;

use App\Models\BaseModel;

class FiscalYear extends BaseModel
{
    protected $fillable = [
        'company_id','name','start_date','end_date',
        'status','is_current','closed_at','closed_by'
    ];

    protected $casts = [
        'start_date' => 'date',
        'end_date'   => 'date',
        'closed_at'  => 'datetime',
        'is_current' => 'boolean',
    ];

    public function company()
    {
        return $this->belongsTo(Company::class);
    }

    public function periods()
    {
        return $this->hasMany(AccountingPeriod::class);
    }

    public function isOpen(): bool
    {
        return $this->status === 'open';
    }
}
