using Kbx.Contracts;
using Kbx.Contracts.Generated;

namespace Modules.OMS.Orders.Register;

public sealed record RegisterOrderRequest(
    Guid? OrderId,
    long? Version,
    [property: KbxFieldKey(KbxFieldKeys.OrderDate)] DateOnly OrderDate,
    [property: KbxFieldKey(KbxFieldKeys.CustomerId)] Guid CustomerId,
    [property: KbxFieldKey(KbxFieldKeys.WarehouseId)] Guid WarehouseId,
    [property: KbxFieldKey(KbxFieldKeys.ReceiverName)] string ReceiverName,
    [property: KbxFieldKey(KbxFieldKeys.Phone)] string Phone,
    [property: KbxFieldKey(KbxFieldKeys.PostalCode)] string? PostalCode,
    [property: KbxFieldKey(KbxFieldKeys.Address1)] string Address1,
    [property: KbxFieldKey(KbxFieldKeys.Address2)] string? Address2,
    IReadOnlyList<RegisterOrderLineRequest> Lines);

public sealed record RegisterOrderLineRequest(
    string ClientId,
    [property: KbxFieldKey(KbxFieldKeys.ItemId)] Guid ItemId,
    [property: KbxFieldKey(KbxFieldKeys.OrderQty)] decimal? OrderQty,
    // Legacy wire compatibility for v12 clients. Remove only in a declared breaking API migration.
    decimal? Quantity,
    [property: KbxFieldKey(KbxFieldKeys.UnitPrice)] decimal UnitPrice,
    [property: KbxFieldKey(KbxFieldKeys.Remark)] string? Remark)
{
    public decimal EffectiveOrderQty => OrderQty ?? Quantity ?? 0m;
}
