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

namespace ERPCore.Dtos.Procurement;

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

public sealed record RfqLineDto(int RfqLineId, int ItemId, decimal Qty);

public sealed record RfqDto(
    int RfqId, string DocNo, int RequisitionId, RfqStatus Status, IReadOnlyList<RfqLineDto> Lines);

/// <summary>Row shape for <c>GET /rfqs</c> — line/quotation counts instead of the lines themselves.</summary>
public sealed record RfqSummaryDto(
    int RfqId, string DocNo, int RequisitionId, RfqStatus Status, int LineCount, int QuotationCount);

public sealed record QuotationLineDto(int ItemId, decimal UnitPrice, int LeadDays);

public sealed record VendorQuotationDto(
    int QuotationId, int RfqId, int VendorId, IReadOnlyList<QuotationLineDto> Lines);

/// <summary>Per-item, per-vendor price matrix for <c>GET /rfqs/{id}/comparison</c>.</summary>
public sealed record RfqComparisonCellDto(int VendorId, int QuotationId, decimal UnitPrice, int LeadDays);
public sealed record RfqComparisonRowDto(int ItemId, decimal Qty, IReadOnlyList<RfqComparisonCellDto> Quotes);
public sealed record RfqComparisonDto(int RfqId, IReadOnlyList<int> VendorIds, IReadOnlyList<RfqComparisonRowDto> Rows);

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

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

public sealed class CreateRfqRequest
{
    [Required] public int RequisitionId { get; set; }
    /// <summary>Vendors the RFQ is issued to (validated for existence; quotations reference them).</summary>
    public List<int> VendorIds { get; set; } = new();
    [Required, MinLength(1)] public List<CreateRfqLineInput> Lines { get; set; } = new();
}

public sealed class CreateQuotationLineInput
{
    [Required] public int ItemId { get; set; }
    [Range(0, double.MaxValue)] public decimal UnitPrice { get; set; }
    [Range(0, int.MaxValue)] public int LeadDays { get; set; }
}

public sealed class CreateQuotationRequest
{
    [Required] public int VendorId { get; set; }
    [Required, MinLength(1)] public List<CreateQuotationLineInput> Lines { get; set; } = new();
}
