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

namespace IamService.API.Application.Validations;

/// <summary>
/// EN: Validator for CreateGroupCommand.
/// VI: Validator cho CreateGroupCommand.
/// </summary>
public class CreateGroupCommandValidator : AbstractValidator<CreateGroupCommand>
{
    public CreateGroupCommandValidator()
    {
        RuleFor(x => x.Name)
            .NotEmpty().WithMessage("Group name is required")
            .MaximumLength(200).WithMessage("Group name cannot exceed 200 characters");

        RuleFor(x => x.OrganizationId)
            .NotEmpty().WithMessage("Organization ID is required");

        RuleFor(x => x.Description)
            .MaximumLength(1000).WithMessage("Description cannot exceed 1000 characters")
            .When(x => x.Description != null);
    }
}

/// <summary>
/// EN: Validator for DeleteGroupCommand.
/// VI: Validator cho DeleteGroupCommand.
/// </summary>
public class DeleteGroupCommandValidator : AbstractValidator<DeleteGroupCommand>
{
    public DeleteGroupCommandValidator()
    {
        RuleFor(x => x.Id)
            .NotEmpty().WithMessage("Group ID is required");
    }
}

/// <summary>
/// EN: Validator for AddGroupMemberCommand.
/// VI: Validator cho AddGroupMemberCommand.
/// </summary>
public class AddGroupMemberCommandValidator : AbstractValidator<AddGroupMemberCommand>
{
    public AddGroupMemberCommandValidator()
    {
        RuleFor(x => x.GroupId)
            .NotEmpty().WithMessage("Group ID is required");

        RuleFor(x => x.UserId)
            .NotEmpty().WithMessage("User ID is required");

        RuleFor(x => x.RoleId)
            .Must(id => id == null || (id >= 1 && id <= 3))
            .WithMessage("Role ID must be 1 (Member), 2 (Admin), or 3 (Owner)");
    }
}

/// <summary>
/// EN: Validator for RemoveGroupMemberCommand.
/// VI: Validator cho RemoveGroupMemberCommand.
/// </summary>
public class RemoveGroupMemberCommandValidator : AbstractValidator<RemoveGroupMemberCommand>
{
    public RemoveGroupMemberCommandValidator()
    {
        RuleFor(x => x.GroupId)
            .NotEmpty().WithMessage("Group ID is required");

        RuleFor(x => x.UserId)
            .NotEmpty().WithMessage("User ID is required");
    }
}
