Files
monorepo/LCU.API.Internal.OnlineLoanApp/CRIF.ACTion/Loan/Individuals/AppPartiesSection.cs
T
2026-03-11 11:18:25 -05:00

112 lines
4.6 KiB
C#

using System.Xml.Linq;
using CRIF.ACTion.Common;
using CRIF.ACTion.Common.Builders;
using CRIF.ACTion.Configuration;
using Landmark.OLA.Models;
namespace CRIF.ACTion.Loan.Individuals
{
public class AppPartiesSection : CrifRequestSection
{
public AppPartiesSection(XNamespace sectionNamespace, CrifSettings settings)
: base(sectionNamespace, "appParties", settings)
{
}
public void AddIndividualParty(IReferenceable individual, PartyType partyType, bool hasOptedOutTCPA = false)
{
var borrowerTypeString = partyType == PartyType.primaryBorrower ? "primaryBorrower" : "borrower";
var individualParty = new XElement(CrifNamespaces.App + borrowerTypeString,
new XAttribute(CrifNamespaces.Common + "idRef", individual.Id),
new XAttribute(CrifNamespaces.Common + "partyType", "Individual"),
new XAttribute(CrifNamespaces.App + "isCollateralGrantorFL", false)
);
individualParty.Add(GetCustomField(partyType, hasOptedOutTCPA));
AddContent(individualParty);
}
private XElement GetTCPACustomField()
{
var customField = GetBoolFieldLinkElement(CrifConstants.TCPA_Opt_Out_Field_Id,
true, "IndividualApplicant");
return customField;
}
private XElement GetCustomField(PartyType type, bool includeTCPAOptOut)
{
var fieldValue = type switch
{
PartyType.NonSigningSpouseMarriedToCoBorrower => CrifConstants.Borrower_IsApplicantNonSigningSpouse_Field_NonSigningMarriedToCo,
PartyType.NonSigningSpouseMarriedToPrimary => CrifConstants.Borrower_IsApplicantNonSigningSpouse_Field_NonSigningMarriedToPrimary,
_ => CrifConstants.Borrower_IsApplicantNonSigningSpouse_Field_Borrower,
};
var customField = GetLookupFieldLinkElement(CrifConstants.Borrower_IsApplicantNonSigningSpouse_Field_Id,
fieldValue, "IndividualApplicant");
if (includeTCPAOptOut)
{
var tcpaField = GetTCPACustomField();
var fieldsElementWithTCPA = new XElement(CrifNamespaces.App + "fields", customField, tcpaField);
return fieldsElementWithTCPA;
}
var fieldsElement = new XElement(CrifNamespaces.App + "fields", customField);
return fieldsElement;
}
public void SetSourceChannel(Guid channelId)
{
var sourceChannel = new XElement(CrifNamespaces.App + "sourceChannel",
new XAttribute(CrifNamespaces.Common + "idRef", channelId),
new XAttribute(CrifNamespaces.Common + "partyType", "Channel"));
AddContent(sourceChannel);
}
public void SetServicingChannel(Guid channelId)
{
var servicingChannel = new XElement(CrifNamespaces.App + "servicingChannel",
new XAttribute(CrifNamespaces.Common + "idRef", channelId),
new XAttribute(CrifNamespaces.Common + "partyType", "Channel"));
AddContent(servicingChannel);
}
private static XElement GetLookupFieldLinkElement(int Id, int value, string fieldLevel)
{
var lookupFieldLinkElement = new XElement(CrifNamespaces.Common + "lookupFieldLink",
new XAttribute(CrifNamespaces.Common + "value", value),
new XElement(CrifNamespaces.Common + "customLookupField",
new XAttribute(CrifNamespaces.Common + "ID", Id),
new XAttribute(CrifNamespaces.Common + "fieldLevel", fieldLevel)));
return lookupFieldLinkElement;
}
private static XElement GetBoolFieldLinkElement(int Id, bool value, string fieldLevel)
{
var lookupFieldLinkElement = new XElement(CrifNamespaces.Common + "boolFieldLink",
new XAttribute(CrifNamespaces.Common + "value", value),
new XElement(CrifNamespaces.Common + "customLookupField",
new XAttribute(CrifNamespaces.Common + "ID", Id),
new XAttribute(CrifNamespaces.Common + "fieldLevel", fieldLevel)));
return lookupFieldLinkElement;
}
public enum PartyType
{
primaryBorrower,
borrower,
NonSigningSpouseMarriedToPrimary,
NonSigningSpouseMarriedToCoBorrower,
}
}
}