using FluentValidation;
using TakeoutSaaS.Application.Identity.Commands;

namespace TakeoutSaaS.Application.Identity.Validators;

/// <summary>
/// 批量用户操作命令验证器。
/// </summary>
public sealed class BatchIdentityUserOperationCommandValidator : AbstractValidator<BatchIdentityUserOperationCommand>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public BatchIdentityUserOperationCommandValidator()
    {
        RuleFor(x => x.Operation).IsInEnum();
        RuleFor(x => x.UserIds).NotEmpty().Must(ids => ids.Length <= 100)
            .WithMessage("单次最多只能选择 100 个用户");
        RuleForEach(x => x.UserIds)
            .Must(value => long.TryParse(value, out _))
            .WithMessage("用户 ID 必须为有效的数字字符串");
        RuleFor(x => x.TenantId).GreaterThan(0).When(x => x.TenantId.HasValue);
    }
}
