using Books.Api.Domain.JournalEntryDrafts;
using EventFlow.Commands;

namespace Books.Api.Commands.JournalEntryDrafts;

/// <summary>
/// Command to create a new journal entry draft.
/// VoucherNumber is required by Bogføringsloven § 7, Stk. 4.
/// </summary>
public class CreateJournalEntryDraftCommand(
    JournalEntryDraftId aggregateId,
    string companyId,
    string name,
    string createdBy,
    string voucherNumber,
    string? extractionData = null)
    : Command<JournalEntryDraftAggregate, JournalEntryDraftId>(aggregateId)
{
    public string CompanyId { get; } = companyId;
    public string Name { get; } = name;
    public string CreatedBy { get; } = createdBy;
    /// <summary>
    /// Bilagsnummer - unique document number per company.
    /// </summary>
    public string VoucherNumber { get; } = voucherNumber;
    /// <summary>
    /// Full AI extraction data as JSON string.
    /// Contains vendor CVR, amounts, VAT, due date, payment reference, line items, etc.
    /// </summary>
    public string? ExtractionData { get; } = extractionData;
}

/// <summary>
/// Command to update a journal entry draft (auto-save).
/// Includes VAT codes per line and attachment references.
/// </summary>
public class UpdateJournalEntryDraftCommand(
    JournalEntryDraftId aggregateId,
    string? name,
    DateOnly? documentDate,
    string? description,
    string? fiscalYearId,
    List<DraftLine> lines,
    List<string>? attachmentIds = null)
    : Command<JournalEntryDraftAggregate, JournalEntryDraftId>(aggregateId)
{
    public string? Name { get; } = name;
    /// <summary>
    /// Bilagsdato - the date of the transaction/document (e.g., invoice date)
    /// </summary>
    public DateOnly? DocumentDate { get; } = documentDate;
    public string? Description { get; } = description;
    public string? FiscalYearId { get; } = fiscalYearId;
    public List<DraftLine> Lines { get; } = lines;
    /// <summary>
    /// References to attached documents (bilag) - required by Bogføringsloven § 6.
    /// </summary>
    public List<string> AttachmentIds { get; } = attachmentIds ?? [];
}

public class MarkJournalEntryDraftPostedCommand(
    JournalEntryDraftId aggregateId,
    string transactionId,
    string postedBy)
    : Command<JournalEntryDraftAggregate, JournalEntryDraftId>(aggregateId)
{
    public string TransactionId { get; } = transactionId;
    public string PostedBy { get; } = postedBy;
}

public class DiscardJournalEntryDraftCommand(
    JournalEntryDraftId aggregateId,
    string discardedBy)
    : Command<JournalEntryDraftAggregate, JournalEntryDraftId>(aggregateId)
{
    public string DiscardedBy { get; } = discardedBy;
}
