using FluentValidation; using Landmark.OLA.Models.Assets.Enums; using Landmark.OLA.Models.Loan.Enums; namespace Landmark.OLA.Models.Loan.Validators { class VehicleValidator : AbstractValidator { private readonly Dictionary> _VehiclesToLoans = new() { { VehicleType.Automobile, new List { LoanType.V_Vehicle, LoanType.V_VehiclePreapproval, } }, { VehicleType.Motorcycle, new List { LoanType.V_Vehicle, LoanType.V_VehiclePreapproval, } }, { VehicleType.Boat, new List { LoanType.M_Boat, } }, { VehicleType.ATV, new List { LoanType.P_Powersport, } }, { VehicleType.PWC, new List { LoanType.P_Powersport, } }, { VehicleType.RecreationalVehicle, new List { LoanType.P_Powersport, } }, { VehicleType.Snowmobile, new List { LoanType.P_Powersport, } }, { VehicleType.TrailerMotorHome, new List { LoanType.T_TrailerMotorhome, } }, }; public VehicleValidator() { RuleFor(x => x.Vehicle.Type).Must((x, vehicleType) => IsAllowedVehicleTypeForLoan(x.LoanType.Value, vehicleType.Value)) .WithMessage($"Vehicle type is not allowed for this loan type."); } private bool IsAllowedVehicleTypeForLoan(LoanType loanType, VehicleType vehicleType) { if (_VehiclesToLoans.TryGetValue(vehicleType, out var loanTypeList)) { return loanTypeList.Contains(loanType); } return false; } } }