using FluentValidation;

namespace TeleWave.Application.Programming.Groups.UpdateGroup;

public sealed class UpdateGroupCommandValidator : AbstractValidator<UpdateGroupCommand>
{
    public UpdateGroupCommandValidator()
    {
        RuleFor(x => x.Name).NotEmpty().MaximumLength(256);
        RuleFor(x => x.Description).MaximumLength(2048);

        When(
            x => x.Filter is not null,
            () =>
            {
                RuleFor(x => x.Filter!.YearMin)
                    .InclusiveBetween(1870, 2200)
                    .When(x => x.Filter!.YearMin is not null);
                RuleFor(x => x.Filter!.YearMax)
                    .InclusiveBetween(1870, 2200)
                    .When(x => x.Filter!.YearMax is not null);
                RuleFor(x => x.Filter!.UnitMinutesMin)
                    .GreaterThanOrEqualTo(0)
                    .When(x => x.Filter!.UnitMinutesMin is not null);
                RuleFor(x => x.Filter!.UnitMinutesMax)
                    .GreaterThanOrEqualTo(0)
                    .When(x => x.Filter!.UnitMinutesMax is not null);
            }
        );
    }
}
