<?php

namespace App\Models;

use App\Traits\ModelCounterTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class TreasuryExit extends Model
{
    use HasFactory, SoftDeletes, ModelCounterTrait;

    protected $fillable = [
        'category_id',
        'date',
        'amount',
        'title',
        'description',
        'attachment',
        'code',
        'is_valid',
        'validation_date',
    ];

    public function category()
    {
        return $this->belongsTo(TreasuryCategory::class);
    }

    public static function booted(): void {
        static::creating(function(TreasuryExit $exit) {
            $exit->code = $exit->codeGenerator([
                "prefix" => "TRS",
                "model" => "TreasuryExit",
                "length" => 5,
            ]);
        });
    }
}
