using FastEndpoints;
using FluentValidation;

namespace Modules.OMS.Orders.Register;

public sealed class RegisterOrderValidator : Validator<RegisterOrderRequest>
{
    public RegisterOrderValidator()
    {
        RuleFor(x => x.OrderDate).NotEmpty().WithErrorCode("ORDER_DATE_REQUIRED");
        RuleFor(x => x.CustomerId).NotEmpty().WithErrorCode("CUSTOMER_REQUIRED");
        RuleFor(x => x.WarehouseId).NotEmpty().WithErrorCode("WAREHOUSE_REQUIRED");
        RuleFor(x => x.ReceiverName).NotEmpty().MaximumLength(100).WithErrorCode("RECEIVER_REQUIRED");
        RuleFor(x => x.Phone).NotEmpty().MaximumLength(50).WithErrorCode("PHONE_REQUIRED");
        RuleFor(x => x.Address1).NotEmpty().MaximumLength(500).WithErrorCode("ADDRESS_REQUIRED");
        RuleFor(x => x.Lines).NotEmpty().WithErrorCode("ORDER_LINE_REQUIRED");

        // Row-aware line validation is deliberately performed in the handler so the
        // KBX response can return the stable ClientId as rowKey instead of Lines[7].OrderQty.
    }
}
