using FluentValidation;

using Microsoft.EntityFrameworkCore;

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

namespace Monitoring.Features.Users.UpdateUser;

public class UpdateUserValidator : AbstractValidator<UpdateUserRequest>
{
	public UpdateUserValidator()
	{
		_ = 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)}");
	}
}
