using BuddyFinance.Common.Helpers; using BuddyFinance.Integration.Models.Enums; using BuddyFinance.Integration.Transunion.TransUnionService; using BuddyFinance.MEF.Concepts; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BuddyFinance.Integration.Transunion.Mappers { public static class Mapper { public static BureauEnquiry01 ToBureauEnquiry01(this Model.Profile profile, Model.Profile buddyFinance, Model.GlobalSetup globalSetup) { var address1 = profile.ProfileAddresses.FirstOrDefault(i => i.AddressTypeId == (int)AddressTypeEnum.PhysicalAddress); var address2 = profile.ProfileAddresses.FirstOrDefault(i => i.AddressTypeId == (int)AddressTypeEnum.PostalAddress); var securitycode = globalSetup.TransUnionSecurityCode; var subscribercode = globalSetup.TransUnionSubscriberCode; var idnumber = new IdentityNumber(profile.IdentificationNumber); return new BureauEnquiry01 { Address1Period = "0", Address2Suburb = address2?.Line2.ToUpper(), Address2City = address2?.City.ToUpper(), Address2Line1 = address2?.Line1.ToUpper(), Address2Line2 = address2?.Line2.ToUpper(), Address2ProvinceCode = address2?.Province.ToTransunionProvince(), Address2Period = "0", Address2PostalCode = address2?.PostalCode, AddressLine1 = address1?.Line1.ToUpper(), AddressLine2 = address1?.Line2.ToUpper(), BankAccountNumber = profile.BankingDetail?.AccountNumber.ToUpper(), BankBranch = profile.BankingDetail?.BranchName.ToUpper(), BankBranchCode = profile.BankingDetail?.BranchCode.ToUpper(), BankName = profile.BankingDetail?.BankName.ToUpper(), BatchNumber = "", BirthDate = idnumber.DateOfBirth.ToString("ddMMyyyy"), BranchNumber = "", CellNo = profile.ContactNumber, City = address1.City.ToUpper(), ClientReference = "", ClientRequestID = Guid.NewGuid().ToString(), EmailAddress = profile.EmailAddress.ToUpper(), Employer = profile.EmploymentDetail?.EmployerName.ToUpper(), EmploymentPeriod = (profile.EmploymentDetail == null || profile.EmploymentDetail?.EmploymentStartDate == null) ? null : ((DateTime.Now - profile.EmploymentDetail.EmploymentStartDate.Value).TotalDays / 30).ToString("N0"), EnquirerContactName = buddyFinance.Name.ToUpper(), EnquirerContactPhoneNo = buddyFinance.ContactNumber, EnquiryAmount = "", EnquiryType = "TBA", Forename1 = profile.Name.ToUpper(), Forename2 = "", Forename3 = "", HomeTelCode = "", HomeTelNo = "", IdentityNo1 = idnumber.Number, IdentityNo2 = "", MaidenName = "", MaritalStatus = "", NoOfDependants = "", Occupation = "", OperatorIdentity = "", OwnerTenant = "", PostalCode = address1?.PostalCode, ProvinceCode = address1?.Province.ToTransunionProvince(), Salary = profile.EmploymentDetail?.GrossMonthlyIncome.GetValueOrDefault().ToString("N2", CultureInfo.InvariantCulture).Replace(",", ""), SecurityCode = securitycode, Sex = idnumber.Gender.ToString().Substring(0, 1).ToUpper(), SpouseForename1 = "", SpouseForename2 = "", SubscriberCode = subscribercode, Suburb = address1?.Line2.ToUpper(), Surname = profile.Surname.ToUpper(), Title = profile.Title.ToUpper(), WorkTelCode = "012115705", WorkTelNo = "" }; } public static GetCustomerCreditProfileResult ToCustomerCreditProfile(this BureauResponse response) { //int score = 0; int.TryParse(response.ScoreCardBX04?[0].Indicators[0].Score, out int score); return new GetCustomerCreditProfileResult { ErrorCode = response.ErrorCode == "Success" ? 0 : 1, Message = response.ErrorMessage, CreditScore = score, Judgements = response.JudgementsNJ09?.Select(i => new CustomerJudgement { CaptureDate = i.CaptureDate, JudgmentDate = i.JudgmentDate, AdministrationMonthlyAmount = i.AdministrationMonthlyAmount, AdministrationNumberOfMonths = i.AdministrationNumberOfMonths, Amount = i.Amount, Remarks = i.Remarks }).ToList(), Accounts = response.PaymentProfileNP15?.Where(i => double.TryParse(i.CurrentBalance, out double bal) == true && bal > 0) .Select(a => new CustomerAccount { Amount = double.TryParse(a.Instalment, out double installment) ? installment : 0, Balance = double.TryParse(a.CurrentBalance, out double balance) ? balance : 0, Status = MEF.Enums.AccountStatusEnum.Active }).ToList(), BasicCustomerInformation = new BasicCustomerInformation { MatchIndicator = new MatchIndicator { DefiniteMatchCount = response.ConsEnqTransInfo0102?.DefiniteMatchCount, PossibleMatchCount = response.ConsEnqTransInfo0102?.PossibleMatchCount, }, DeceasedDate = response.ConsumerInfoNO04?.DeceasedDate, NumberOfDependants = response.ConsumerInfoNO04?.Dependants, FullNames = $"{response.ConsumerInfoNO04?.Title} {response.ConsumerInfoNO04?.Forename1} {response.ConsumerInfoNO04?.Forename2} {response.ConsumerInfoNO04?.Surname}", FirstName = response.ConsumerInfoNO04?.Forename1, LastName = response.ConsumerInfoNO04?.Surname } }; } public static string ToTransunionProvince(this Model.Province province) { switch (province.Description) { case "Gauteng": return "GP"; case "KwaZulu - Natal": return "KN"; case "Limpopo": return "NP"; case "North - West": return "NW"; case "Northern Cape": return "NC"; case "Western Cape": return "WC"; case "Eastern Cape": return "EC"; case "Freestate": return "FS"; case "Mpumalanga": return "MP"; default: return ""; } } } }