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

namespace ERPCore.Dtos.Stock;

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

public sealed record CountLineDto(int CountLineId, int ItemId, int? BinId, decimal SystemQty, decimal? CountedQty, decimal? Variance);

public sealed record CountDto(
    int CountId, string DocNo, int WarehouseId, CountType CountType, CountStatus Status,
    int CreatedBy, DateTime CreatedAt, IReadOnlyList<CountLineDto> Lines);

/// <summary>Row shape for <c>GET /stock-counts</c> — line count instead of the lines themselves.</summary>
public sealed record CountSummaryDto(
    int CountId, string DocNo, int WarehouseId, CountType CountType, CountStatus Status,
    int CreatedBy, DateTime CreatedAt, int LineCount);

public sealed record CountPostResultDto(int CountId, CountStatus Status, int? AdjustmentId, string? GlJournalNo, IReadOnlyList<int> LedgerRefs);

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

public sealed class CreateCountRequest
{
    [Required] public int WarehouseId { get; set; }
    [Required, EnumDataType(typeof(CountType))] public CountType CountType { get; set; }
    [Required, MinLength(1)] public List<int> ItemIds { get; set; } = new();
}

public sealed class EnterCountLineInput
{
    [Required] public int CountLineId { get; set; }
    [Range(0, double.MaxValue)] public decimal CountedQty { get; set; }
}

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