using FluentValidation; using ReC.Application.Common.Procedures.InsertProcedure; namespace ReC.Application.Common.Validations; public class InsertObjectProcedureValidator : AbstractValidator { public InsertObjectProcedureValidator() { // ENTITY must be one of the allowed values RuleFor(x => x.Entity) .NotEmpty() .Must(e => e is "ACTION" or "ENDPOINT" or "ENDPOINT_AUTH" or "ENDPOINT_PARAMS" or "PROFILE" or "RESULT") .WithMessage("ENTITY must be one of: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT."); // ACTION validation When(x => x.Entity == "ACTION", () => { RuleFor(x => x.Action.ProfileId) .NotNull() .WithMessage("ACTION requires ActionProfileId (maps to @pACTION_PROFILE_ID)."); RuleFor(x => x.Action.EndpointId) .NotNull() .WithMessage("ACTION requires ActionEndpointId (maps to @pACTION_ENDPOINT_ID)."); }); // ENDPOINT validation When(x => x.Entity == "ENDPOINT", () => { RuleFor(x => x.Endpoint.Uri) .NotEmpty() .WithMessage("ENDPOINT requires EndpointUri (maps to @pENDPOINT_URI).") .MaximumLength(2000); }); // PROFILE validation When(x => x.Entity == "PROFILE", () => { RuleFor(x => x.Profile.Name) .NotEmpty() .WithMessage("PROFILE requires ProfileName (maps to @pPROFILE_NAME).") .MaximumLength(50); RuleFor(x => x.Profile.Mandantor) .MaximumLength(50) .When(x => x.Profile.Mandantor != null); RuleFor(x => x.Profile.Description) .MaximumLength(250) .When(x => x.Profile.Description != null); }); // RESULT validation When(x => x.Entity == "RESULT", () => { RuleFor(x => x.Result.ActionId) .NotNull() .WithMessage("RESULT requires ResultActionId (maps to @pRESULT_ACTION_ID)."); RuleFor(x => x.Result.StatusId) .NotNull() .WithMessage("RESULT requires ResultStatusId (maps to @pRESULT_STATUS_ID)."); }); // ENDPOINT_PARAMS validation When(x => x.Entity == "ENDPOINT_PARAMS", () => { RuleFor(x => x.EndpointParams.GroupId) .NotNull() .WithMessage("ENDPOINT_PARAMS requires EndpointParamsGroupId (maps to @pENDPOINT_PARAMS_GROUP_ID)."); }); // Simple length guards for some string fields (optional but cheap) RuleFor(x => x.AddedWho) .MaximumLength(50) .When(x => x.AddedWho != null); RuleFor(x => x.Endpoint.Description) .MaximumLength(250) .When(x => x.Endpoint.Description != null); RuleFor(x => x.EndpointAuth.Description) .MaximumLength(250) .When(x => x.EndpointAuth.Description != null); } }