<?php

namespace App\Models;

use App\Enums\PartyLedger;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

final class JournalLine extends Model
{
    public $timestamps = false;

    protected $fillable = [
        'journal_entry_id', 'line_number', 'account_id', 'party_id', 'party_ledger',
        'branch_id', 'department_id', 'cost_center_id', 'description', 'debit',
        'credit', 'currency_code', 'exchange_rate',
    ];

    protected function casts(): array
    {
        return [
            'party_ledger' => PartyLedger::class,
            'debit' => 'decimal:4',
            'credit' => 'decimal:4',
            'exchange_rate' => 'decimal:8',
        ];
    }

    public function journalEntry(): BelongsTo { return $this->belongsTo(JournalEntry::class, 'journal_entry_id'); }
    public function journal(): BelongsTo { return $this->journalEntry(); }
    public function account(): BelongsTo { return $this->belongsTo(Account::class); }
    public function party(): BelongsTo { return $this->belongsTo(Party::class); }
}
