using FluentValidation;

namespace ColaFlow.Modules.ProjectManagement.Application.Commands.UpdateSprint;

/// <summary>
/// Validator for UpdateSprintCommand
/// </summary>
public sealed class UpdateSprintCommandValidator : AbstractValidator<UpdateSprintCommand>
{
    public UpdateSprintCommandValidator()
    {
        RuleFor(x => x.SprintId)
            .NotEmpty()
            .WithMessage("Sprint ID is required");

        RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("Sprint name is required")
            .MaximumLength(200)
            .WithMessage("Sprint name cannot exceed 200 characters");

        RuleFor(x => x.StartDate)
            .NotEmpty()
            .WithMessage("Start date is required");

        RuleFor(x => x.EndDate)
            .NotEmpty()
            .WithMessage("End date is required")
            .GreaterThan(x => x.StartDate)
            .WithMessage("End date must be after start date");

        RuleFor(x => x)
            .Must(x => (x.EndDate - x.StartDate).Days <= 30)
            .WithMessage("Sprint duration cannot exceed 30 days")
            .Must(x => (x.EndDate - x.StartDate).Days >= 1)
            .WithMessage("Sprint duration must be at least 1 day");
    }
}
