using FluentValidation;

namespace Baya.Application.Features.Identity.Commands.UpdatePatient;

public sealed class UpdatePatientCommandValidator : AbstractValidator<UpdatePatientCommand>
{
    public UpdatePatientCommandValidator()
    {
        // Id is supplied by the route, not the request body, so it is not validated here.
        RuleFor(x => x.DisplayName).NotEmpty().MaximumLength(200);
        RuleFor(x => x.FirstName).MaximumLength(100);
        RuleFor(x => x.LastName).MaximumLength(100);
        RuleFor(x => x.BloodType).MaximumLength(10);
        RuleFor(x => x.Gender)
            .Must(PatientRules.IsValidGender)
            .WithMessage("Gender is required and must be 'male' or 'female'.");
        RuleFor(x => x.BirthDate)
            .NotEqual(default(DateOnly))
            .Must(PatientRules.IsNotFuture)
            .WithMessage("Birth date cannot be in the future.");
        RuleFor(x => x.Relation)
            .Must(PatientRules.IsValidRelation)
            .WithMessage("Relation must be one of parent, spouse, child, self.");
        RuleFor(x => x.Conditions)
            .Must(PatientRules.AreValidConditions)
            .WithMessage("Each condition must be a non-empty code up to 40 characters.");
    }
}
