| | | 1 | | using ArturRios.Heimdall.Domain.Enums; |
| | | 2 | | using ArturRios.Heimdall.Shared.Messages; |
| | | 3 | | using FluentValidation; |
| | | 4 | | |
| | | 5 | | namespace ArturRios.Heimdall.Command.Input.Validation; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Shape validation for <see cref="UpdatePersonCommand" /> (UC-08 step 2). Business rules that |
| | | 9 | | /// need data access — existence, authorization, email uniqueness, scope ownership — are enforced |
| | | 10 | | /// by the handler. |
| | | 11 | | /// </summary> |
| | | 12 | | public class UpdatePersonCommandValidator : AbstractValidator<UpdatePersonCommand> |
| | | 13 | | { |
| | 41 | 14 | | public UpdatePersonCommandValidator() |
| | | 15 | | { |
| | 41 | 16 | | RuleFor(command => command.Name) |
| | 41 | 17 | | .NotEmpty().WithMessage(PersonMessages.NameRequired) |
| | 41 | 18 | | .MaximumLength(200).WithMessage(PersonMessages.NameTooLong); |
| | | 19 | | |
| | 41 | 20 | | RuleFor(command => command.Email) |
| | 41 | 21 | | .NotEmpty().WithMessage(PersonMessages.EmailRequired) |
| | 41 | 22 | | .EmailAddress().WithMessage(PersonMessages.EmailInvalid); |
| | | 23 | | |
| | | 24 | | // The role is optional: null means "leave it unchanged". When supplied it must name one of |
| | | 25 | | // the three defined roles; whether the transition is *allowed* is the handler's decision. |
| | 41 | 26 | | RuleFor(command => command.RoleId) |
| | 8 | 27 | | .Must(role => role is (int)Roles.SystemAdmin or (int)Roles.ScopeAdmin or (int)Roles.User) |
| | 41 | 28 | | .When(command => command.RoleId is not null) |
| | 41 | 29 | | .WithMessage(PersonMessages.UnknownRole); |
| | 41 | 30 | | } |
| | | 31 | | } |