// EN: FluentValidation validators for inventory commands.
// VI: FluentValidation validators cho inventory commands.

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

namespace InventoryService.API.Application.Validations;

/// <summary>
/// EN: Validator for CreateInventoryItemCommand.
/// VI: Validator cho CreateInventoryItemCommand.
/// </summary>
public class CreateInventoryItemCommandValidator : AbstractValidator<CreateInventoryItemCommand>
{
    public CreateInventoryItemCommandValidator()
    {
        RuleFor(x => x.ShopId)
            .NotEmpty()
            .WithMessage("Shop ID is required / Shop ID bắt buộc");

        RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("Name is required / Tên bắt buộc")
            .MaximumLength(200)
            .WithMessage("Name must be 200 characters or less / Tên tối đa 200 ký tự");

        RuleFor(x => x.ItemTypeId)
            .InclusiveBetween(1, 3)
            .WithMessage("Item type must be 1 (RawMaterial), 2 (FinishedGood), or 3 (Consumable) / Loại item phải là 1, 2 hoặc 3");

        RuleFor(x => x.Unit)
            .NotEmpty()
            .WithMessage("Unit is required / Đơn vị bắt buộc")
            .MaximumLength(20)
            .WithMessage("Unit must be 20 characters or less / Đơn vị tối đa 20 ký tự");

        RuleFor(x => x.CostPerUnit)
            .GreaterThanOrEqualTo(0)
            .WithMessage("Cost per unit must be >= 0 / Giá đơn vị phải >= 0");

        RuleFor(x => x.InitialQuantity)
            .GreaterThanOrEqualTo(0)
            .WithMessage("Initial quantity must be >= 0 / Số lượng ban đầu phải >= 0");

        RuleFor(x => x.ReorderLevel)
            .GreaterThanOrEqualTo(0)
            .WithMessage("Reorder level must be >= 0 / Mức đặt hàng lại phải >= 0");
    }
}

/// <summary>
/// EN: Validator for StockInCommand.
/// VI: Validator cho StockInCommand.
/// </summary>
public class StockInCommandValidator : AbstractValidator<StockInCommand>
{
    public StockInCommandValidator()
    {
        RuleFor(x => x.ProductId)
            .NotEmpty()
            .WithMessage("Product ID is required / Product ID bắt buộc");

        RuleFor(x => x.ShopId)
            .NotEmpty()
            .WithMessage("Shop ID is required / Shop ID bắt buộc");

        RuleFor(x => x.Amount)
            .GreaterThan(0)
            .WithMessage("Amount must be greater than 0 / Số lượng phải lớn hơn 0");
    }
}

/// <summary>
/// EN: Validator for StockOutCommand.
/// VI: Validator cho StockOutCommand.
/// </summary>
public class StockOutCommandValidator : AbstractValidator<StockOutCommand>
{
    public StockOutCommandValidator()
    {
        RuleFor(x => x.ProductId)
            .NotEmpty()
            .WithMessage("Product ID is required / Product ID bắt buộc");

        RuleFor(x => x.ShopId)
            .NotEmpty()
            .WithMessage("Shop ID is required / Shop ID bắt buộc");

        RuleFor(x => x.Amount)
            .GreaterThan(0)
            .WithMessage("Amount must be greater than 0 / Số lượng phải lớn hơn 0");
    }
}

/// <summary>
/// EN: Validator for ReserveStockCommand.
/// VI: Validator cho ReserveStockCommand.
/// </summary>
public class ReserveStockCommandValidator : AbstractValidator<ReserveStockCommand>
{
    public ReserveStockCommandValidator()
    {
        RuleFor(x => x.ProductId)
            .NotEmpty()
            .WithMessage("Product ID is required / Product ID bắt buộc");

        RuleFor(x => x.ShopId)
            .NotEmpty()
            .WithMessage("Shop ID is required / Shop ID bắt buộc");

        RuleFor(x => x.Amount)
            .GreaterThan(0)
            .WithMessage("Amount must be greater than 0 / Số lượng phải lớn hơn 0");

        RuleFor(x => x.OrderId)
            .NotEmpty()
            .WithMessage("Order ID is required / Order ID bắt buộc");
    }
}

/// <summary>
/// EN: Validator for ReleaseReservationCommand.
/// VI: Validator cho ReleaseReservationCommand.
/// </summary>
public class ReleaseReservationCommandValidator : AbstractValidator<ReleaseReservationCommand>
{
    public ReleaseReservationCommandValidator()
    {
        RuleFor(x => x.ProductId)
            .NotEmpty()
            .WithMessage("Product ID is required / Product ID bắt buộc");

        RuleFor(x => x.ShopId)
            .NotEmpty()
            .WithMessage("Shop ID is required / Shop ID bắt buộc");

        RuleFor(x => x.Amount)
            .GreaterThan(0)
            .WithMessage("Amount must be greater than 0 / Số lượng phải lớn hơn 0");

        RuleFor(x => x.OrderId)
            .NotEmpty()
            .WithMessage("Order ID is required / Order ID bắt buộc");
    }
}

/// <summary>
/// EN: Validator for AdjustStockCommand.
/// VI: Validator cho AdjustStockCommand.
/// </summary>
public class AdjustStockCommandValidator : AbstractValidator<AdjustStockCommand>
{
    public AdjustStockCommandValidator()
    {
        RuleFor(x => x.ProductId)
            .NotEmpty()
            .WithMessage("Product ID is required / Product ID bắt buộc");

        RuleFor(x => x.ShopId)
            .NotEmpty()
            .WithMessage("Shop ID is required / Shop ID bắt buộc");

        RuleFor(x => x.NewQuantity)
            .GreaterThanOrEqualTo(0)
            .WithMessage("New quantity must be >= 0 / Số lượng mới phải >= 0");

        RuleFor(x => x.Notes)
            .NotEmpty()
            .WithMessage("Notes are required for adjustment / Ghi chú bắt buộc cho điều chỉnh");
    }
}

/// <summary>
/// EN: Validator for SetLowStockAlertCommand.
/// VI: Validator cho SetLowStockAlertCommand.
/// </summary>
public class SetLowStockAlertCommandValidator : AbstractValidator<SetLowStockAlertCommand>
{
    public SetLowStockAlertCommandValidator()
    {
        RuleFor(x => x.ShopId)
            .NotEmpty()
            .WithMessage("Shop ID is required / Shop ID bắt buộc");

        RuleFor(x => x.ProductId)
            .NotEmpty()
            .WithMessage("Product ID is required / Product ID bắt buộc");

        RuleFor(x => x.MinimumLevel)
            .GreaterThanOrEqualTo(0)
            .WithMessage("Minimum level must be >= 0 / Mức tối thiểu phải >= 0");
    }
}
