// EN: Validators for Role commands (create, update, delete, assign, remove).
// VI: Validators cho cac commands Role (tao, cap nhat, xoa, gan, go).

using FluentValidation;
using IamService.API.Application.Commands.Roles;

namespace IamService.API.Application.Validations;

/// <summary>
/// EN: Validator for CreateRoleCommand.
/// VI: Validator cho CreateRoleCommand.
/// </summary>
public class CreateRoleCommandValidator : AbstractValidator<CreateRoleCommand>
{
    public CreateRoleCommandValidator()
    {
        RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("Role name is required / Ten role la bat buoc")
            .MaximumLength(100)
            .WithMessage("Role name must not exceed 100 characters / Ten role khong vuot qua 100 ky tu")
            .Matches(@"^[a-zA-Z0-9_\-\.]+$")
            .WithMessage("Role name must contain only letters, numbers, underscores, hyphens, and dots / Ten role chi chua chu cai, so, gach duoi, gach ngang va dau cham");

        RuleFor(x => x.Description)
            .MaximumLength(500)
            .WithMessage("Description must not exceed 500 characters / Mo ta khong vuot qua 500 ky tu")
            .When(x => x.Description != null);
    }
}

/// <summary>
/// EN: Validator for UpdateRoleCommand.
/// VI: Validator cho UpdateRoleCommand.
/// </summary>
public class UpdateRoleCommandValidator : AbstractValidator<UpdateRoleCommand>
{
    public UpdateRoleCommandValidator()
    {
        RuleFor(x => x.RoleId)
            .NotEmpty()
            .WithMessage("Role ID is required / Role ID la bat buoc");

        RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("Role name is required / Ten role la bat buoc")
            .MaximumLength(100)
            .WithMessage("Role name must not exceed 100 characters / Ten role khong vuot qua 100 ky tu")
            .Matches(@"^[a-zA-Z0-9_\-\.]+$")
            .WithMessage("Role name must contain only letters, numbers, underscores, hyphens, and dots / Ten role chi chua chu cai, so, gach duoi, gach ngang va dau cham");

        RuleFor(x => x.Description)
            .MaximumLength(500)
            .WithMessage("Description must not exceed 500 characters / Mo ta khong vuot qua 500 ky tu")
            .When(x => x.Description != null);
    }
}

/// <summary>
/// EN: Validator for DeleteRoleCommand.
/// VI: Validator cho DeleteRoleCommand.
/// </summary>
public class DeleteRoleCommandValidator : AbstractValidator<DeleteRoleCommand>
{
    public DeleteRoleCommandValidator()
    {
        RuleFor(x => x.RoleId)
            .NotEmpty()
            .WithMessage("Role ID is required / Role ID la bat buoc");
    }
}

/// <summary>
/// EN: Validator for AssignRoleToUserCommand.
/// VI: Validator cho AssignRoleToUserCommand.
/// </summary>
public class AssignRoleToUserCommandValidator : AbstractValidator<AssignRoleToUserCommand>
{
    public AssignRoleToUserCommandValidator()
    {
        RuleFor(x => x.UserId)
            .NotEmpty()
            .WithMessage("User ID is required / User ID la bat buoc");

        RuleFor(x => x.RoleName)
            .NotEmpty()
            .WithMessage("Role name is required / Ten role la bat buoc")
            .MaximumLength(100)
            .WithMessage("Role name must not exceed 100 characters / Ten role khong vuot qua 100 ky tu");
    }
}

/// <summary>
/// EN: Validator for RemoveRoleFromUserCommand.
/// VI: Validator cho RemoveRoleFromUserCommand.
/// </summary>
public class RemoveRoleFromUserCommandValidator : AbstractValidator<RemoveRoleFromUserCommand>
{
    public RemoveRoleFromUserCommandValidator()
    {
        RuleFor(x => x.UserId)
            .NotEmpty()
            .WithMessage("User ID is required / User ID la bat buoc");

        RuleFor(x => x.RoleName)
            .NotEmpty()
            .WithMessage("Role name is required / Ten role la bat buoc")
            .MaximumLength(100)
            .WithMessage("Role name must not exceed 100 characters / Ten role khong vuot qua 100 ky tu");
    }
}
