using System.ComponentModel.DataAnnotations;
using ERPCore.Domain.Enums;

namespace ERPCore.Dtos.Stock;

// Responses (docs/11 §5.4) ------------------------------------------------------

public sealed record TransferLineDto(
    int TransferLineId, int ItemId, int? SrcBinId, int? DestBinId, int? BatchId, decimal Qty, decimal QtyReceived);

public sealed record TransferDto(
    int TransferId, string DocNo, int SrcWarehouseId, int DestWarehouseId,
    TransferStatus Status, int CreatedBy, DateTime CreatedAt, IReadOnlyList<TransferLineDto> Lines);

/// <summary>Row shape for <c>GET /stock-transfers</c> — line count instead of the lines themselves.</summary>
public sealed record TransferSummaryDto(
    int TransferId, string DocNo, int SrcWarehouseId, int DestWarehouseId,
    TransferStatus Status, int CreatedBy, DateTime CreatedAt, int LineCount);

public sealed record ConsumedLayerDto(int LayerId, decimal QtyConsumed, decimal UnitCost);

public sealed record DispatchResultDto(
    int TransferId, TransferStatus Status, IReadOnlyList<ConsumedLayerDto> ConsumedLayers, IReadOnlyList<int> LedgerRefs);

public sealed record TransferCreatedLayerDto(int LayerId, int WarehouseId, decimal QtyReceived, decimal UnitCost);

public sealed record ReceiveResultDto(
    int TransferId, TransferStatus Status, IReadOnlyList<TransferCreatedLayerDto> CreatedLayers, IReadOnlyList<int> LedgerRefs);

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

public sealed class CreateTransferLineInput
{
    [Required] public int ItemId { get; set; }
    public int? SrcBinId { get; set; }
    public int? DestBinId { get; set; }
    public int? BatchId { get; set; }
    [Range(0.0001, double.MaxValue)] public decimal Qty { get; set; }
}

public sealed class CreateTransferRequest
{
    [Required] public int SrcWarehouseId { get; set; }
    [Required] public int DestWarehouseId { get; set; }
    [Required, MinLength(1)] public List<CreateTransferLineInput> Lines { get; set; } = new();
}

public sealed class ReceiveTransferLineInput
{
    [Required] public int TransferLineId { get; set; }
    [Range(0.0001, double.MaxValue)] public decimal Qty { get; set; }
}

public sealed class ReceiveTransferRequest
{
    [Required, MinLength(1)] public List<ReceiveTransferLineInput> Lines { get; set; } = new();
}
