using FluentValidation;
using IWS5.Core.DTO.IAdmin.Servers;
using IWS5.Core.Helpers;
using IWS5.DatabaseAccess.Interfaces.IAdmin;

namespace IWS5.Services.Validators.IAdmin.Servers;

public class CreateServerRequestValidator : AbstractValidator<CreateServerRequestDTO>
{
    public CreateServerRequestValidator(IServerRepository serverRepository)
    {
        RuleFor(x => x.HostName)
            .NotEmpty().WithMessage("Server host name is required.")
            .MaximumLength(255).WithMessage("Server host name must not exceed 255 characters.")
            .Must(hostName => serverRepository.GetByNameAsync(hostName).Result == null).WithMessage("Server host name must be unique.");

        RuleFor(x => x.LogLevel)
            .GreaterThan(0).WithMessage("Server log level must be greater than 0.");

        RuleFor(x => x.LogFile)
            .NotEmpty().WithMessage("Server log file is required.")
            .MaximumLength(255).WithMessage("Server log file must not exceed 255 characters.");

        RuleFor(x => x.Limit)
            .GreaterThan(0).WithMessage("Server limit must be greater than 0.");

        RuleFor(x => x.Interval)
            .GreaterThan(0).WithMessage("Server interval must be greater than 0.");
    }
}
