// EN: FluentValidation validator for DeductInventoryCommand.
// VI: FluentValidation validator cho DeductInventoryCommand.

using FluentValidation;
using InventoryService.API.Application.Commands.DeductInventory;

namespace InventoryService.API.Application.Validations;

/// <summary>
/// EN: Validates DeductInventoryCommand before processing.
/// VI: Validate DeductInventoryCommand trước khi xử lý.
/// </summary>
public class DeductInventoryCommandValidator : AbstractValidator<DeductInventoryCommand>
{
    public DeductInventoryCommandValidator()
    {
        RuleFor(x => x.ShopId)
            .NotEmpty()
            .WithMessage("Shop ID is required / Shop ID là bắt buộc");

        RuleFor(x => x.ReferenceId)
            .NotEmpty()
            .WithMessage("Reference ID is required / Reference ID là bắt buộc");

        RuleFor(x => x.ReferenceType)
            .NotEmpty()
            .WithMessage("Reference type is required / Loại tham chiếu là bắt buộc");

        RuleFor(x => x.Items)
            .NotEmpty()
            .WithMessage("At least one deduction item is required / Cần ít nhất một item trừ kho");

        RuleForEach(x => x.Items).ChildRules(item =>
        {
            item.RuleFor(i => i.InventoryItemId)
                .NotEmpty()
                .WithMessage("Inventory item ID is required / Inventory item ID là bắt buộc");

            item.RuleFor(i => i.Amount)
                .GreaterThan(0)
                .WithMessage("Amount must be positive / Số lượng phải dương");
        });
    }
}
