using FluentValidation;

using Monitoring.Common.Validators;
using Monitoring.Features.Reports.Contracts;
using Monitoring.Models;

namespace Monitoring.Features.Reports.Validators;

public class GetReportListRequestValidator : AbstractValidator<GetReportListRequest>
{
	public GetReportListRequestValidator()
	{
		RuleFor(x => x).SetValidator(new TableStateValidator());

		RuleFor(x => x.Search)
			.Null()
			.NotEmpty()
			.WithMessage("Search cannot be empty")
			.When(x => !string.IsNullOrWhiteSpace(x.Search));

		RuleFor(x => x.ByDate)
			.Must(x => x == SortDirection.Ascending || x == SortDirection.Descending)
			.When(x => !string.IsNullOrEmpty(x.ByDate));

		RuleFor(x => x.Alphabetic)
			.Must(x => x == SortDirection.Ascending || x == SortDirection.Descending)
			.When(x => !string.IsNullOrEmpty(x.Alphabetic));
	}
}
