using FluentValidation;

using Monitoring.Common;
using Monitoring.Core.Domain.UserPrimitives;

namespace Monitoring.Features.Users.CreateUser;

public class CreateUserValidator : AbstractValidator<CreateUserRequest>
{
	public CreateUserValidator()
	{
		_ = RuleFor(x => x.Username).NotEmpty()
			.MinimumLength(UserName.MinLength)
			.MaximumLength(UserName.MaxLength);

		_ = RuleFor(x => x.Password).NotEmpty()
			.MinimumLength(Password.MinLength)
			.MaximumLength(Password.MaxLength);

		_ = RuleFor(x => x.Role).Must(x => Roles.All.Contains(x))
			.WithMessage($"Role must be one of {string.Join(", ", Roles.All)}");
	}
}
