<?php

namespace App\Domain\Financial\Models;

use App\Domain\Financial\Enums\ExpenseCategory;
use App\Domain\Financial\Enums\PaymentMethod;
use App\Domain\Shared\Traits\BelongsToAcademy;
use App\Domain\Shared\Traits\HasUuid;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class Expense extends Model
{
    use HasUuid, BelongsToAcademy, SoftDeletes;

    protected $fillable = [
        'academy_id',
        'branch_id',
        'category',
        'amount',
        'description',
        'recipient_name',
        'payment_method',
        'receipt_reference',
        'expense_date',
        'notes',
        'created_by',
    ];

    protected function casts(): array
    {
        return [
            'category' => ExpenseCategory::class,
            'amount' => 'integer',
            'payment_method' => PaymentMethod::class,
            'expense_date' => 'date',
        ];
    }

    public function branch(): BelongsTo
    {
        return $this->belongsTo(\App\Domain\Identity\Models\Branch::class);
    }

    public function creator(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
