using FluentValidation;

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

/// <summary>
/// Validator for CreateSprintCommand
/// </summary>
public sealed class CreateSprintCommandValidator : AbstractValidator<CreateSprintCommand>
{
    public CreateSprintCommandValidator()
    {
        RuleFor(x => x.ProjectId)
            .NotEmpty().WithMessage("ProjectId is required");

        RuleFor(x => x.Name)
            .NotEmpty().WithMessage("Name is required")
            .MaximumLength(200).WithMessage("Name must not exceed 200 characters");

        RuleFor(x => x.Goal)
            .MaximumLength(1000).WithMessage("Goal must not exceed 1000 characters");

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

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

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

        RuleFor(x => x.CreatedBy)
            .NotEmpty().WithMessage("CreatedBy is required");
    }
}
