using CashLineERP.Domain.Common;

namespace CashLineERP.Domain.Tax;

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

    public long AccountsReceivableInvoiceId { get; private set; }

    public string? SubmissionReference { get; private set; }

    public string? EtaUuid { get; private set; }

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

    public DateTime? SubmittedAtUtc { get; private set; }

    public DateTime? ResponseAtUtc { get; private set; }

    public string? ErrorCode { get; private set; }

    public string? ErrorMessage { get; private set; }

    public string? PayloadText { get; private set; }

    public string? ResponseText { get; private set; }

    public EtaSubmissionLog(
        long accountsReceivableInvoiceId,
        string? submissionReference,
        string statusCode,
        DateTime? submittedAtUtc,
        string? payloadText)
    {
        AccountsReceivableInvoiceId = accountsReceivableInvoiceId;
        SubmissionReference = submissionReference;
        StatusCode = statusCode;
        SubmittedAtUtc = submittedAtUtc;
        PayloadText = payloadText;
    }

    private EtaSubmissionLog()
    {
    }

    public void RecordResponse(
        string statusCode,
        string? etaUuid,
        string? responseText,
        string? errorCode,
        string? errorMessage,
        long actorUserId)
    {
        StatusCode = statusCode;
        EtaUuid = etaUuid;
        ResponseText = responseText;
        ErrorCode = errorCode;
        ErrorMessage = errorMessage;
        ResponseAtUtc = DateTime.UtcNow;
        Touch(actorUserId);
    }
}
