<?php
# ────────────── lee_gwena ──────────────
# Code by: ashley_gwena
# Created: 2026-03-12
# Notes: Cashbook model for bank configuration
# ───────────────────────────────────────

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Cashbook extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $table = 'cashbooks';

    protected $fillable = [
        'name',
        'is_trust',
        'currency',
        'gl_account_id',
        'account_number',
        'created_by',
        'updated_by',
    ];

    protected $casts = [
        'is_trust' => 'boolean',
    ];

    // Relationships
    public function currency()
    {
        return $this->belongsTo(Currency::class, 'currency', 'currency_code');
    }

    public function glAccount()
    {
        return $this->belongsTo(GeneralLedgerParentAccount::class, 'gl_account_id');
    }

    public function cashbookEntries()
    {
        return $this->hasMany(CashbookEntry::class);
    }

    public function scopeTrust($query)
    {
        return $query->where('is_trust', true);
    }
}
