<?php

namespace App\Models;

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

/**
 * Cashbook Model
 *
 * Represents a cashbook entry in the system, linked to a general ledger account.
 */
class Cashbook extends Model
{
    use HasFactory;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = "cashbooks";

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'code',
        'gl_account_id',
        'description',
        'account_type',
    ];

    /**
     * The model's default attribute values.
     *
     * @var array<string, mixed>
     */
    protected $attributes = [
        'account_type' => 'cash',
    ];


/**
     * Relationship to GL Account (MainAccount).
     */
    public function mainAccount()
    {
        return $this->belongsTo(MainAccount::class, 'gl_account_id');
    }
}
