using System.ComponentModel.DataAnnotations;

namespace ERPCore.Dtos.Sales;

// Responses -----------------------------------------------------------------------

/// <summary>Qty/revenue sold for one item across a closed (or about-to-close) day, for the day-end report.
/// Merges sales-slip and bundle-sale lines for the same item into one row.</summary>
public sealed record SalesDayEndItemLineDto(int ItemId, string Sku, string Name, decimal Qty, decimal Revenue);

public sealed record SalesDayEndDto(
    int SalesDayEndId, string DocNo, int CashierUserId, DateOnly BusinessDate,
    int SlipCount, int BundleCount, decimal Subtotal, decimal DiscountTotal, decimal TaxTotal, decimal GrandTotal,
    decimal CostOfGoodsSold, string? GlJournalNo, DateTime? GlPostedAt, int ClosedBy, DateTime ClosedAt,
    IReadOnlyList<string> SlipNumbers, IReadOnlyList<string> BundleNumbers, IReadOnlyList<SalesDayEndItemLineDto> ItemBreakdown);

public sealed record SalesDayEndSummaryDto(
    int SalesDayEndId, string DocNo, int CashierUserId, DateOnly BusinessDate,
    int SlipCount, int BundleCount, decimal GrandTotal, string? GlJournalNo, DateTime ClosedAt);

/// <summary>What closing right now would include — call before <c>POST /sales-day-end</c> so the
/// cashier can see the day's totals, and any still-Draft slips/bundles blocking the close.</summary>
public sealed record SalesDayEndPreviewDto(
    int CashierUserId, DateOnly BusinessDate, bool AlreadyClosed,
    int SlipCount, int BundleCount, decimal Subtotal, decimal DiscountTotal, decimal TaxTotal, decimal GrandTotal,
    IReadOnlyList<string> SlipNumbers, IReadOnlyList<string> BundleNumbers,
    IReadOnlyList<DraftSlipBlockingCloseDto> DraftSlipsBlockingClose,
    IReadOnlyList<DraftBundleBlockingCloseDto> DraftBundleSalesBlockingClose);

public sealed record DraftSlipBlockingCloseDto(int SalesSlipId, string SlipNo, decimal GrandTotal);
public sealed record DraftBundleBlockingCloseDto(int BundleSaleId, string BundleNo, decimal GrandTotal);

// Requests ------------------------------------------------------------------------

public sealed class CreateSalesDayEndRequest
{
    [Required] public int CashierUserId { get; set; }
    /// <summary>Defaults to today (UTC) when omitted.</summary>
    public DateOnly? BusinessDate { get; set; }
}
