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

namespace ERPCore.Dtos.Stock;

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

public sealed record AdjustmentLineDto(int AdjLineId, int ItemId, int? BinId, int? BatchId, decimal QtyDelta);

public sealed record AdjustmentDto(
    int AdjustmentId, string DocNo, int WarehouseId, int ReasonCodeId, AdjustmentStatus Status,
    int CreatedBy, DateTime CreatedAt, string? GlJournalNo, DateTime? GlPostedAt,
    IReadOnlyList<AdjustmentLineDto> Lines, IReadOnlyList<int> LedgerRefs);

/// <summary>Row shape for <c>GET /stock-adjustments</c> — no lines/ledgerRefs (those need a per-row query).</summary>
public sealed record AdjustmentSummaryDto(
    int AdjustmentId, string DocNo, int WarehouseId, int ReasonCodeId, AdjustmentStatus Status,
    int CreatedBy, DateTime CreatedAt, int LineCount, string? GlJournalNo);

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

public sealed class CreateAdjustmentLineInput
{
    [Required] public int ItemId { get; set; }
    public int? BinId { get; set; }
    public int? BatchId { get; set; }
    /// <summary>Signed base-UOM delta: negative consumes FIFO layers, positive adds stock.</summary>
    public decimal QtyDelta { get; set; }
}

public sealed class CreateAdjustmentRequest
{
    [Required] public int WarehouseId { get; set; }
    /// <summary>Nullable so an omitted value is a distinct <c>REASON_CODE_REQUIRED</c> error, not 0.</summary>
    public int? ReasonCodeId { get; set; }
    [Required, MinLength(1)] public List<CreateAdjustmentLineInput> Lines { get; set; } = new();
}
