using CashLineERP.Domain.Common;

namespace CashLineERP.Domain.Finance;

public sealed class BankStatement : Entity
{
    public long Id { get; private set; }

    public string StatementNumber { get; private set; } = string.Empty;

    public string BankAccountCode { get; private set; } = string.Empty;

    public DateOnly StatementDate { get; private set; }

    public string CurrencyCode { get; private set; } = "EGP";

    public decimal OpeningBalanceAmount { get; private set; }

    public decimal ClosingBalanceAmount { get; private set; }

    public string ImportStatusCode { get; private set; } = "IMPORTED";

    public List<BankStatementLine> Lines { get; private set; } = [];

    public BankStatement(
        string statementNumber,
        string bankAccountCode,
        DateOnly statementDate,
        string currencyCode,
        decimal openingBalanceAmount,
        decimal closingBalanceAmount)
    {
        StatementNumber = statementNumber;
        BankAccountCode = bankAccountCode;
        StatementDate = statementDate;
        CurrencyCode = currencyCode;
        OpeningBalanceAmount = openingBalanceAmount;
        ClosingBalanceAmount = closingBalanceAmount;
    }

    private BankStatement()
    {
    }

    public void AddLine(
        int lineNumber,
        DateOnly transactionDate,
        string? externalReference,
        string? descriptionText,
        decimal debitAmount,
        decimal creditAmount,
        decimal runningBalanceAmount)
    {
        Lines.Add(new BankStatementLine(
            bankStatementId: Id,
            lineNumber: lineNumber,
            transactionDate: transactionDate,
            externalReference: externalReference,
            descriptionText: descriptionText,
            debitAmount: debitAmount,
            creditAmount: creditAmount,
            runningBalanceAmount: runningBalanceAmount));
    }
}
