<?php

namespace App\Domain\Financial\Models;

use App\Domain\Financial\Enums\ExpenseCategory;
use App\Domain\Financial\Enums\PaymentMethod;
use App\Domain\Shared\Traits\BelongsToBranch;
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, BelongsToBranch, SoftDeletes;

    protected $fillable = [
        'academy_id',
        'branch_id',
        'category',
        'amount',
        'description',
        'recipient_name',
        'payment_method',
        'receipt_reference',
        'expense_date',
        'notes',
        'attachment_path',
        'attachment_name',
        'status',
        'cancelled_by',
        'cancelled_at',
        'cancellation_reason',
        'created_by',
    ];

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

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

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

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