using FruitBank.Common.Enums;

namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Models;

public class PreOrderListRow
{
    public int           PreOrderId      { get; set; }
    public int           CustomerId      { get; set; }
    public string        CustomerName    { get; set; } = string.Empty;
    public string        CustomerEmail   { get; set; } = string.Empty;
    public string        DateOfReceipt   { get; set; } = string.Empty;  // formatted
    public string        CreatedOnUtc    { get; set; } = string.Empty;  // formatted
    public PreOrderStatus Status         { get; set; }
    public string        StatusLabel     { get; set; } = string.Empty;
    public int           ItemCount       { get; set; }
    public int           FulfilledCount  { get; set; }
    public int?          OrderId         { get; set; }  // linked real order, if created
}

public class PreOrderDetailModel
{
    public int            PreOrderId    { get; set; }
    public int            CustomerId    { get; set; }
    public string         CustomerName  { get; set; } = string.Empty;
    public string         CustomerEmail { get; set; } = string.Empty;
    public string         DateOfReceipt { get; set; } = string.Empty;
    public string         CreatedOnUtc  { get; set; } = string.Empty;
    public string         UpdatedOnUtc  { get; set; } = string.Empty;
    public PreOrderStatus Status        { get; set; }
    public string?        CustomerNote  { get; set; }
    public int?           OrderId       { get; set; }
    public List<PreOrderDetailItemRow> Items { get; set; } = new();
}

public class PreOrderDetailItemRow
{
    public int               ItemId            { get; set; }
    public int               ProductId         { get; set; }
    public string            ProductName       { get; set; } = string.Empty;
    public bool              IsMeasurable      { get; set; }
    public int               RequestedQuantity { get; set; }
    public int               FulfilledQuantity { get; set; }
    public decimal           UnitPriceInclTax  { get; set; }
    public PreOrderItemStatus Status           { get; set; }
    public string            StatusLabel       { get; set; } = string.Empty;
}

public class PreOrderDemandRow
{
    public int     ProductId           { get; set; }
    public string  ProductName         { get; set; } = string.Empty;
    public string? Sku                 { get; set; }
    public bool    IsMeasurable        { get; set; }
    public int     TotalRequested      { get; set; }  // sum of RequestedQuantity
    public int     TotalFulfilled      { get; set; }  // sum of FulfilledQuantity
    public int     TotalUnfulfilled    { get; set; }  // TotalRequested - TotalFulfilled
    public int     PreOrderCount       { get; set; }  // distinct preorders containing this product
    public decimal AvgUnitPrice        { get; set; }  // average snapshot price
}
