Files
monorepo/LCU.API.Internal.OnlineLoanApp/Landmark.OLA.Models/Loan/Validators/VehicleValidator.cs
T
2026-03-11 11:18:25 -05:00

81 lines
2.3 KiB
C#

using FluentValidation;
using Landmark.OLA.Models.Assets.Enums;
using Landmark.OLA.Models.Loan.Enums;
namespace Landmark.OLA.Models.Loan.Validators
{
class VehicleValidator : AbstractValidator<LoanApplication>
{
private readonly Dictionary<VehicleType, List<LoanType>> _VehiclesToLoans = new()
{
{ VehicleType.Automobile,
new List<LoanType>
{
LoanType.V_Vehicle,
LoanType.V_VehiclePreapproval,
}
},
{ VehicleType.Motorcycle,
new List<LoanType>
{
LoanType.V_Vehicle,
LoanType.V_VehiclePreapproval,
}
},
{ VehicleType.Boat,
new List<LoanType>
{
LoanType.M_Boat,
}
},
{ VehicleType.ATV,
new List<LoanType>
{
LoanType.P_Powersport,
}
},
{ VehicleType.PWC,
new List<LoanType>
{
LoanType.P_Powersport,
}
},
{ VehicleType.RecreationalVehicle,
new List<LoanType>
{
LoanType.P_Powersport,
}
},
{ VehicleType.Snowmobile,
new List<LoanType>
{
LoanType.P_Powersport,
}
},
{ VehicleType.TrailerMotorHome,
new List<LoanType>
{
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;
}
}
}