<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Expense extends Model
{
    // Mengizinkan semua field diisi termasuk fund_source
    protected $guarded = [];

    protected $casts = [
        'amount' => 'float',
        'expense_date' => 'date',
    ];

    // Relasi ke Kategori Biaya
    public function expenseCategory(): BelongsTo
    {
        return $this->belongsTo(ExpenseCategory::class);
    }

    // Relasi ke Cabang
    public function branch(): BelongsTo 
    { 
        return $this->belongsTo(Branch::class); 
    }

    // Relasi ke User pembuat
    public function user(): BelongsTo 
    { 
        return $this->belongsTo(User::class); 
    }

    // --- TAMBAHAN RELASI BARU UNTUK SUMBER DANA ---
    public function fundAccount(): BelongsTo
    {
        // PERBAIKAN: Ubah referensi dari Account::class menjadi ChartOfAccount::class
        return $this->belongsTo(ChartOfAccount::class, 'fund_account_id');
    }
}