<?php

namespace App\Models;

use App\Models\Concerns\BelongsToBranch;
use App\Models\Concerns\HasAuditColumns;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class FeeType extends Model
{
    use BelongsToBranch;
    use HasAuditColumns;
    use SoftDeletes;

    protected $fillable = ['branch_id', 'name', 'code', 'frequency', 'default_amount', 'discountable', 'is_active'];

    protected function casts(): array
    {
        return ['default_amount' => 'decimal:2', 'discountable' => 'boolean', 'is_active' => 'boolean'];
    }

    public const FREQUENCIES = ['monthly', 'annual', 'one_time'];

    public function structures(): HasMany
    {
        return $this->hasMany(FeeStructure::class);
    }

    public function scopeActive(Builder $q): Builder
    {
        return $q->where('is_active', true);
    }
}
