using System.Xml.Linq; using CRIF.ACTion.Common; using CRIF.ACTion.Common.Builders; using Landmark.OLA.Models.Assets; using Landmark.OLA.Models.Loan.Enums; using static CRIF.ACTion.Common.ContactMechanisms; namespace CRIF.ACTion.Loan.Assets { public class VehicleProperty : IProperty { private readonly Vehicle _vehicle; public VehicleProperty(Vehicle vehicle) { _vehicle = vehicle; } public XElement Build(params XElement[] content) { //If there's no vehicle type, it's likely a preapproval and doesn't need this element if (_vehicle is null || _vehicle.Type is null) return null; var propertyValues = PropertyValues.GetPropertyValues(_vehicle.Type.Value); var propertyElement = new XElement(CrifNamespaces.Common + propertyValues.elementName, new XAttribute(CrifNamespaces.Common + "id", _vehicle.GetOrCreateGuid()), new XAttribute(CrifNamespaces.Common + "propertySubType", propertyValues.PropertySubType), new XAttribute(CrifNamespaces.Common + "yearBuilt", _vehicle.Year.Value), new XAttribute(CrifNamespaces.Common + "initialEstimatedValue", _vehicle.InitialEstimatedValue.Value), new XAttribute(CrifNamespaces.Common + "propertyType", propertyValues.PropertyType)); if ( _vehicle.Type != Landmark.OLA.Models.Assets.Enums.VehicleType.Automobile ) { propertyElement.Add(new XAttribute(CrifNamespaces.Common + "totalValue", _vehicle.InitialEstimatedValue.Value)); } if (_vehicle.HasClearTitle.HasValue) { propertyElement.Add(new XAttribute(CrifNamespaces.Common + "hasClearTitleFL", _vehicle.HasClearTitle.Value)); } if (_vehicle.IsForBusinessUse.HasValue) { var usageType = _vehicle.IsForBusinessUse.Value ? "Business" : "Personal"; propertyElement.Add(new XAttribute(CrifNamespaces.Common + "propertyUsageTypeID", usageType)); } if (_vehicle.IsOwnerOperator.HasValue) { propertyElement.Add(new XAttribute(CrifNamespaces.Common + "isOwnerOperatorFL", _vehicle.IsOwnerOperator.Value)); } if ((_vehicle.Type == Landmark.OLA.Models.Assets.Enums.VehicleType.PWC || _vehicle.Type == Landmark.OLA.Models.Assets.Enums.VehicleType.Boat) && !string.IsNullOrWhiteSpace(_vehicle.VIN)) { propertyElement.Add(new XAttribute(CrifNamespaces.Common + "hullNum", BuilderUtils.FormatCrifData(_vehicle.VIN))); } if (_vehicle.Type == Landmark.OLA.Models.Assets.Enums.VehicleType.Boat && (_vehicle.BoatLength ?? 0) != 0) { propertyElement.Add(new XAttribute(CrifNamespaces.Common + "lengthDesc", _vehicle.BoatLength)); } // Order matters for elements if (_vehicle.Type == Landmark.OLA.Models.Assets.Enums.VehicleType.Boat && _vehicle.BoatAddress is not null) { var contactMechanisms = new XElement(CrifNamespaces.Common + "contactMechanisms"); contactMechanisms.Add(GetAddressContactMechanismElement(_vehicle.BoatAddress.Id, CrifContactMechanism.MarinaAddress)); propertyElement.Add(contactMechanisms); } var valuationsLinkElement = new XElement(CrifNamespaces.Common + "propertyVehicleValuations", new XElement(CrifNamespaces.Common + "propertyVehicleValuation", new XAttribute(CrifNamespaces.Common + "idRef", _vehicle.ValuationId))); propertyElement.Add(valuationsLinkElement); if (_vehicle.Type == Landmark.OLA.Models.Assets.Enums.VehicleType.Boat) { propertyElement.Add(CreateMotorElement(_vehicle)); propertyElement.Add(CreateTrailerElement(_vehicle)); } return propertyElement; } public static XElement CreateMotorElement(Vehicle vehicle) { var motorElement = new XElement(CrifNamespaces.Common + "motors"); var propertyMotorElement = new XElement(CrifNamespaces.Common + "propertyMotor", new XAttribute(CrifNamespaces.Common + "motorNum", 1)); if (!string.IsNullOrWhiteSpace(vehicle.MotorMake)) { propertyMotorElement.Add(new XAttribute(CrifNamespaces.Common + "make", vehicle.MotorMake)); } if (vehicle.MotorYear is not null) { propertyMotorElement.Add(new XAttribute(CrifNamespaces.Common + "yearBuilt", vehicle.MotorYear.Value)); } if (!string.IsNullOrWhiteSpace(vehicle.MotorModel)) { propertyMotorElement.Add(new XAttribute(CrifNamespaces.Common + "model", vehicle.MotorModel)); } if (vehicle.MotorType is not null) { propertyMotorElement.Add(new XAttribute(CrifNamespaces.Common + "engineTypeID", vehicle.MotorType)); } motorElement.Add(propertyMotorElement); return motorElement; } public static XElement CreateTrailerElement(Vehicle vehicle) { var trailerElement = new XElement(CrifNamespaces.Common + "trailer", new XAttribute(CrifNamespaces.Common + "registrationState", "WI")); if (!string.IsNullOrWhiteSpace(vehicle.TrailerType)) { trailerElement.Add(new XAttribute(CrifNamespaces.Common + "propertySubType", vehicle.TrailerType)); } if (vehicle.TrailerYear is not null) { trailerElement.Add(new XAttribute(CrifNamespaces.Common + "yearBuild", vehicle.TrailerYear.Value)); } if (!string.IsNullOrWhiteSpace(vehicle.TrailerMake)) { trailerElement.Add(new XAttribute(CrifNamespaces.Common + "make", vehicle.TrailerMake)); } return trailerElement; } public static XElement GetAddressContactMechanismElement(Guid addressRef, CrifContactMechanism contactMechanismType) { var contactMechanism = new XElement(CrifNamespaces.Common + "contactMechanism", new XAttribute(CrifNamespaces.Common + "contactMechanismType", contactMechanismType), new XElement(CrifNamespaces.Common + "addressRef", new XAttribute(CrifNamespaces.Common + "idRef", addressRef) ), new XElement(CrifNamespaces.Common + "contactMechanismCategory", new XAttribute(CrifNamespaces.Common + "CD", 2) ) ); return contactMechanism; } } }