using FluentValidation;

namespace ColaFlow.Modules.Identity.Application.Commands.RegisterTenant;

public class RegisterTenantCommandValidator : AbstractValidator<RegisterTenantCommand>
{
    public RegisterTenantCommandValidator()
    {
        RuleFor(x => x.TenantName)
            .NotEmpty().WithMessage("Tenant name is required")
            .MinimumLength(2).WithMessage("Tenant name must be at least 2 characters")
            .MaximumLength(100).WithMessage("Tenant name cannot exceed 100 characters");

        RuleFor(x => x.TenantSlug)
            .NotEmpty().WithMessage("Tenant slug is required")
            .MinimumLength(3).WithMessage("Tenant slug must be at least 3 characters")
            .MaximumLength(50).WithMessage("Tenant slug cannot exceed 50 characters")
            .Matches("^[a-z0-9]+(?:-[a-z0-9]+)*$")
            .WithMessage("Tenant slug can only contain lowercase letters, numbers, and hyphens");

        RuleFor(x => x.SubscriptionPlan)
            .NotEmpty().WithMessage("Subscription plan is required")
            .Must(plan => new[] { "Free", "Starter", "Professional", "Enterprise" }.Contains(plan))
            .WithMessage("Invalid subscription plan");

        RuleFor(x => x.AdminEmail)
            .NotEmpty().WithMessage("Admin email is required")
            .EmailAddress().WithMessage("Invalid email format");

        RuleFor(x => x.AdminPassword)
            .NotEmpty().WithMessage("Admin password is required")
            .MinimumLength(8).WithMessage("Password must be at least 8 characters")
            .Matches("[A-Z]").WithMessage("Password must contain at least one uppercase letter")
            .Matches("[a-z]").WithMessage("Password must contain at least one lowercase letter")
            .Matches("[0-9]").WithMessage("Password must contain at least one digit")
            .Matches("[^a-zA-Z0-9]").WithMessage("Password must contain at least one special character");

        RuleFor(x => x.AdminFullName)
            .NotEmpty().WithMessage("Admin full name is required")
            .MinimumLength(2).WithMessage("Full name must be at least 2 characters")
            .MaximumLength(100).WithMessage("Full name cannot exceed 100 characters");
    }
}
