<?php

declare(strict_types=1);

namespace App\Models\Barangay;

use App\Models\Model;

class BarangayBudget extends Model
{
    protected ?string $table = 'barangay_budget';

    protected array $fillable = [
        'hashkey', 'fiscal_year', 'category', 'source',
        'amount', 'description', 'date', 'reference', 'encoded_by',
    ];

    protected array $casts = [
        'amount' => 'decimal:2',
        'date'   => 'date',
    ];

    public function encodedBy()
    {
        return $this->belongsTo(\App\Models\User::class, 'encoded_by');
    }

    public function scopeIncome($query)
    {
        return $query->where('category', 'INCOME');
    }

    public function scopeExpense($query)
    {
        return $query->where('category', 'EXPENSE');
    }

    public function scopeByYear($query, int $year)
    {
        return $query->where('fiscal_year', $year);
    }
}
