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
}
