<?php

namespace App\Models;

class BankStatementLine extends BaseModel
{
    protected $fillable = [
        'company_id',
        'bank_statement_import_id',
        'bank_reconciliation_id',
        'transaction_date',
        'description',
        'reference',
        'debit',
        'credit',
        'balance',
        'matched_ledger_entry_id',
        'matched_at',
    ];

    protected $casts = [
        'transaction_date' => 'date',
        'debit' => 'decimal:2',
        'credit' => 'decimal:2',
        'balance' => 'decimal:2',
        'matched_at' => 'datetime',
    ];

    public function import()
    {
        return $this->belongsTo(BankStatementImport::class, 'bank_statement_import_id');
    }

    public function reconciliation()
    {
        return $this->belongsTo(BankReconciliation::class, 'bank_reconciliation_id');
    }

    public function matchedLedgerEntry()
    {
        return $this->belongsTo(LedgerEntry::class, 'matched_ledger_entry_id');
    }

    public function isMatched(): bool
    {
        return $this->matched_ledger_entry_id !== null;
    }
}
