<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\Client;
use App\Models\Matter;
use App\Models\TrustAccount;

class CashbookEntry extends Model
{
    protected $table = 'cashbook_entries';

    protected $fillable = [
        'cashbook_id',
        'journal_header_id',
        'transaction_date',
        'reference',
        'description',
        'amount',
        'transaction_type',
        'client_id',
        'matter_id',
        'trust_account_id',
        'created_by',
        'updated_by',
    ];

    protected $casts = [
        'transaction_date' => 'date',
        'amount' => 'decimal:2',
    ];

    // Relationships
    public function cashbook()
    {
        return $this->belongsTo(Cashbook::class, 'cashbook_id');
    }

    public function journalHeader()
    {
        return $this->belongsTo(\App\Models\JournalHeader::class, 'journal_header_id');
    }

    public function client()
    {
        return $this->belongsTo(Client::class, 'client_id');
    }

    public function matter()
    {
        return $this->belongsTo(Matter::class, 'matter_id');
    }

    public function trustAccount()
    {
        return $this->belongsTo(TrustAccount::class, 'trust_account_id');
    }
}
