using System.Xml.Linq; using CRIF.ACTion.Common; using CRIF.ACTion.Configuration; using Landmark.OLA.Models.Assets; using Landmark.OLA.Models.Loan; namespace CRIF.ACTion.Loan.Assets { public class AppDetailVehicleSection : AppDetailsSection { private readonly List _content; private XElement _vehicleValuationsElement; public AppDetailVehicleSection(XNamespace sectionNamespace, CrifSettings settings) : base(sectionNamespace, "appDetailVehicle", settings, "Fixed", "Installment") { _content = []; } public void AddPropertyDetails(Vehicle vehicle) { //If there's no vehicle type, it's likely a preapproval and doesn't need the appDetailProperties element if (vehicle is null || vehicle.Type is null) { return; } var appDetailPropertiesElement = new XElement(CrifNamespaces.App + "appDetailProperties"); var propertyValues = PropertyValues.GetPropertyValues(vehicle.Type.Value); var isCollateralFL = true; var isTradeInFL = false; var statusID = "Active"; var includeInLTVCalculations = true; var appDetailPropertyElement = new XElement(CrifNamespaces.App + "appDetailProperty", new XAttribute(CrifNamespaces.Common + "idRef", vehicle.GetOrCreateGuid()), new XAttribute(CrifNamespaces.Common + "propertyType", propertyValues.PropertyType), new XAttribute(CrifNamespaces.Common + "propertySubType", propertyValues.PropertySubType), new XAttribute(CrifNamespaces.App + "isCollateralFL", isCollateralFL), new XAttribute(CrifNamespaces.App + "isTradeInFL", isTradeInFL), new XAttribute(CrifNamespaces.App + "statusID", statusID), new XAttribute(CrifNamespaces.App + "includeInLTVCalculations", includeInLTVCalculations), new XAttribute(CrifNamespaces.App + "collateralTypeID", propertyValues.CollateralId) ); appDetailPropertiesElement.Add(appDetailPropertyElement); _vehicleValuationsElement = new XElement(CrifNamespaces.App + "vehicleValuations", new XElement(CrifNamespaces.App + "appDetailVehicleValuation", new XAttribute(CrifNamespaces.Common + "idRef", vehicle.ValuationId), new XAttribute(CrifNamespaces.App + "valueType", vehicle.ValuationType.Value.ToString()))); //TODO: What does valuationType mean? _content.Add(appDetailPropertiesElement); } public void AddSalesPriceDetails(LoanApplication loanApplication) { _content.Add(new XAttribute(CrifNamespaces.App + "initialSalesPrice", loanApplication.RequestedAmount)); } public override void SetDetails(LoanApplication loanApplication, Guid channelRef, object[] additionalContent = null, XElement fieldsElement = null, XElement vehicleValuationsElement = null) { base.SetDetails(loanApplication, channelRef, [.. _content], vehicleValuationsElement: _vehicleValuationsElement); } } }