<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\Account;

class CashMutation extends Model
{
    protected $table = 'cash_mutations'; //

    protected $fillable = [
        'mutation_date', 'from_account_id', 'to_account_id', 
        'amount', 'type', 'note', 'branch_id', 'user_id'
    ];

    // Eager load agar Next.js tidak menerima data kosong
    protected $with = ['fromAccount', 'toAccount'];

    public function fromAccount() {
        // Gunakan \App\Models\Account untuk memastikan path benar[cite: 5]
        return $this->belongsTo(Account::class, 'from_account_id');
    }

    public function toAccount() {
        return $this->belongsTo(Account::class, 'to_account_id');
    }
}