Skip to content

Instantly share code, notes, and snippets.

@matiasdim
Created March 5, 2021 12:44
Show Gist options
  • Save matiasdim/127a46e8f00e92b8f2d5f21aa0733771 to your computer and use it in GitHub Desktop.
Save matiasdim/127a46e8f00e92b8f2d5f21aa0733771 to your computer and use it in GitHub Desktop.
//
// ArrangementConverter.swift
// Banesco
//
// Created by Matías Gil Echavarría on 4/03/21.
//
import ArrangementsClient2
import RetailAccountsAndTransactionsJourney
import ClientCommon
struct ArrangementConverter {
static func convert(_ summaryAggregatedBalance: ArrangementsClient2.SummaryAggregatedBalance) -> RetailAccountsAndTransactionsJourney.SummaryAggregatedBalance {
return .init(currency: summaryAggregatedBalance.currency,
value: summaryAggregatedBalance.value,
additions: summaryAggregatedBalance.additions)
}
// MARK: - Current Account Converter
static func convert(_ account: ArrangementsClient2.CurrentAccount) -> RetailAccountsAndTransactionsJourney.CurrentAccount {
return .init(bookedBalance: account.bookedBalance,
availableBalance: account.availableBalance,
creditLimit: account.creditLimit,
iban: account.IBAN,
bban: account.BBAN,
currency: account.currency,
urgentTransferAllowed: account.urgentTransferAllowed,
bic: account.BIC,
bankBranchCode: account.bankBranchCode,
accountInterestRate: account.accountInterestRate,
valueDateBalance: account.valueDateBalance,
creditLimitUsage: account.creditLimitUsage,
creditLimitInterestRate: account.creditLimitInterestRate,
creditLimitExpiryDate: account.creditLimitExpiryDate,
accruedInterest: account.accruedInterest,
debitCardsItems: [] /* account.debitCardsItems.map(DebitCardItem.init) */,
accountHolderNames: account.accountHolderNames,
startDate: account.startDate,
minimumRequiredBalance: account.minimumRequiredBalance,
accountHolderAddressLine1: account.accountHolderAddressLine1,
accountHolderAddressLine2: account.accountHolderAddressLine2,
accountHolderStreetName: account.accountHolderStreetName,
town: account.town,
postCode: account.postCode,
countrySubDivision: account.countrySubDivision,
creditAccount: account.creditAccount,
debitAccount: account.debitAccount,
accountHolderCountry: account.accountHolderCountry,
additions: account.additions,
identifier: account.id,
name: account.name,
externalTransferAllowed: account.externalTransferAllowed,
crossCurrencyAllowed: account.crossCurrencyAllowed,
productKindName: account.productKindName,
productTypeName: account.productTypeName,
bankAlias: account.bankAlias,
sourceId: account.sourceId,
visible: account.visible,
accountOpeningDate: account.accountOpeningDate,
lastUpdateDate: account.lastUpdateDate,
userPreferences: nil /* account.userPreferences != nil ? UserPreferences(account.userPreferences!): nil*/,
state: nil /* account.state != nil ? StateItem(account.state!): nil */,
parentId: account.parentId,
subArrangements: nil /* account.subArrangements != nil ? account.subArrangements!.map(BaseProduct.init): nil */,
financialInstitutionId: account.financialInstitutionId,
lastSyncDate: account.lastSyncDate)
}
static func convert(_ accounts: ArrangementsClient2.CurrentAccountProductKinds) -> RetailAccountsAndTransactionsJourney.CurrentAccountProductKinds? {
return .init(products: accounts.products.map(Self.convert),
additions: accounts.additions,
name: accounts.name,
aggregatedBalance: accounts.aggregatedBalance != nil ? Self.convert(accounts.aggregatedBalance!) : nil)
}
// MARK: - Savings Account Converter
static func convert(_ account: ArrangementsClient2.SavingsAccount) -> RetailAccountsAndTransactionsJourney.SavingsAccount {
return .init(bookedBalance: account.bookedBalance,
availableBalance: account.availableBalance,
accruedInterest: account.accruedInterest,
iban: account.IBAN,
bban: account.BBAN,
currency: account.currency,
urgentTransferAllowed: account.urgentTransferAllowed,
bic: account.BIC,
bankBranchCode: account.bankBranchCode,
accountInterestRate: account.accountInterestRate,
minimumRequiredBalance: account.minimumRequiredBalance,
startDate: account.startDate,
termUnit: nil, //account.termUnit,
termNumber: account.termNumber,
maturityDate: account.maturityDate,
maturityAmount: account.maturityAmount,
autoRenewalIndicator: account.autoRenewalIndicator,
interestPaymentFrequencyUnit: nil,//account.interestPaymentFrequencyUnit,
interestPaymentFrequencyNumber: account.interestPaymentFrequencyNumber,
principalAmount: account.principalAmount,
interestSettlementAccount: account.interestSettlementAccount,
accountHolderNames: account.accountHolderNames,
valueDateBalance: account.valueDateBalance,
accountHolderAddressLine1: account.accountHolderAddressLine1,
accountHolderAddressLine2: account.accountHolderAddressLine2,
accountHolderStreetName: account.accountHolderStreetName,
town: account.town,
postCode: account.postCode,
countrySubDivision: account.countrySubDivision,
accountHolderCountry: account.accountHolderCountry,
creditAccount: account.creditAccount,
debitAccount: account.debitAccount,
additions: account.additions,
identifier: account.id,
name: account.name,
externalTransferAllowed: account.externalTransferAllowed,
crossCurrencyAllowed: account.crossCurrencyAllowed,
productKindName: account.productKindName,
productTypeName: account.productTypeName,
bankAlias: account.bankAlias,
sourceId: account.sourceId,
visible: account.visible,
accountOpeningDate: account.accountOpeningDate,
lastUpdateDate: account.lastUpdateDate,
userPreferences: nil, //account.userPreferences,
state: nil, // account.state,
parentId: account.parentId,
subArrangements: nil, //account.subArrangements,
financialInstitutionId: account.financialInstitutionId,
lastSyncDate: account.lastSyncDate)
}
static func convert(_ accounts: ArrangementsClient2.SavingsAccountProductKinds) -> RetailAccountsAndTransactionsJourney.SavingsAccountProductKinds? {
return .init(products: accounts.products.map(Self.convert),
additions: accounts.additions,
name: accounts.name,
aggregatedBalance: accounts.aggregatedBalance != nil ? Self.convert(accounts.aggregatedBalance!) : nil)
}
// MARK: - Term Deposit Converter
static func convert(_ account: ArrangementsClient2.TermDeposit) -> RetailAccountsAndTransactionsJourney.TermDeposit {
return .init(bookedBalance: account.bookedBalance,
principalAmount: account.principalAmount,
accruedInterest: account.accruedInterest,
iban: account.IBAN,
bban: account.BBAN,
currency: account.currency,
urgentTransferAllowed: account.urgentTransferAllowed,
productNumber: account.productNumber,
accountInterestRate: account.accountInterestRate,
startDate: account.startDate,
termUnit: nil,//account.termUnit,
termNumber: account.termNumber,
maturityDate: account.maturityDate,
maturityAmount: account.maturityAmount,
autoRenewalIndicator: account.autoRenewalIndicator,
interestPaymentFrequencyUnit: nil,//account.interestPaymentFrequencyUnit,
interestPaymentFrequencyNumber: account.interestPaymentFrequencyNumber,
interestSettlementAccount: account.interestSettlementAccount,
valueDateBalance: account.valueDateBalance,
accountHolderNames: account.accountHolderNames,
outstandingPrincipalAmount: account.outstandingPrincipalAmount,
creditAccount: account.creditAccount,
debitAccount: account.debitAccount,
minimumRequiredBalance: account.minimumRequiredBalance,
additions: account.additions,
identifier: account.id,
name: account.name,
externalTransferAllowed: account.externalTransferAllowed,
crossCurrencyAllowed: account.crossCurrencyAllowed,
productKindName: account.productKindName,
productTypeName: account.productTypeName,
bankAlias: account.bankAlias,
sourceId: account.sourceId,
visible: account.visible,
accountOpeningDate: account.accountOpeningDate,
lastUpdateDate: account.lastUpdateDate,
userPreferences: nil,//account.userPreferences,
state: nil,//account.state,
parentId: account.parentId,
subArrangements: nil,//account.subArrangements,
financialInstitutionId: account.financialInstitutionId,
lastSyncDate: account.lastSyncDate)
}
static func convert(_ accounts: ArrangementsClient2.TermDepositProductKinds) -> RetailAccountsAndTransactionsJourney.TermDepositProductKinds? {
return .init(products: accounts.products.map(Self.convert),
additions: accounts.additions,
name: accounts.name,
aggregatedBalance: accounts.aggregatedBalance != nil ? Self.convert(accounts.aggregatedBalance!) : nil)
}
// MARK: - Loans Converter
static func convert(_ account: ArrangementsClient2.Loan) -> RetailAccountsAndTransactionsJourney.Loan {
return .init(bookedBalance: account.bookedBalance,
principalAmount: account.principalAmount,
currency: account.currency,
urgentTransferAllowed: account.urgentTransferAllowed,
productNumber: account.productNumber,
accountInterestRate: account.accountInterestRate,
termUnit: nil,//account.termUnit,
termNumber: account.termNumber,
outstandingPrincipalAmount: account.outstandingPrincipalAmount,
monthlyInstalmentAmount: account.monthlyInstalmentAmount,
amountInArrear: account.amountInArrear,
interestSettlementAccount: account.interestSettlementAccount,
accruedInterest: account.accruedInterest,
accountHolderNames: account.accountHolderNames,
maturityDate: account.maturityDate,
valueDateBalance: account.valueDateBalance,
creditAccount: account.creditAccount,
debitAccount: account.debitAccount,
iban: account.IBAN,
bban: account.BBAN,
additions: account.additions,
identifier: account.id,
name: account.name,
externalTransferAllowed: account.externalTransferAllowed,
crossCurrencyAllowed: account.crossCurrencyAllowed,
productKindName: account.productKindName,
productTypeName: account.productTypeName,
bankAlias: account.bankAlias,
sourceId: account.sourceId,
visible: account.visible,
accountOpeningDate: account.accountOpeningDate,
lastUpdateDate: account.lastUpdateDate,
userPreferences: nil,//account.userPreferences,
state: nil,//account.state,
parentId: account.parentId,
subArrangements: nil,//account.subArrangements,
financialInstitutionId: account.financialInstitutionId,
lastSyncDate: account.lastSyncDate)
}
static func convert(_ accounts: ArrangementsClient2.LoanProductKinds) -> RetailAccountsAndTransactionsJourney.LoanProductKinds? {
return .init(products: accounts.products.map(Self.convert),
additions: accounts.additions,
name: accounts.name,
aggregatedBalance: accounts.aggregatedBalance != nil ? Self.convert(accounts.aggregatedBalance!) : nil)
}
// MARK: - Credit Card Converter
static func convert(_ account: ArrangementsClient2.CreditCard) -> RetailAccountsAndTransactionsJourney.CreditCard {
return .init(bookedBalance: account.bookedBalance,
availableBalance: account.availableBalance,
creditLimit: account.creditLimit,
number: account.number,
currency: account.currency,
urgentTransferAllowed: account.urgentTransferAllowed,
cardNumber: account.cardNumber,
creditCardAccountNumber: account.creditCardAccountNumber,
validThru: account.validThru,
applicableInterestRate: account.applicableInterestRate,
remainingCredit: account.remainingCredit,
outstandingPayment: account.outstandingPayment,
minimumPayment: account.minimumPayment,
minimumPaymentDueDate: account.minimumPaymentDueDate,
accountInterestRate: account.accountInterestRate,
accountHolderNames: account.accountHolderNames,
creditLimitUsage: account.creditLimitUsage,
creditLimitInterestRate: account.creditLimitInterestRate,
accruedInterest: account.accruedInterest,
additions: account.additions,
identifier: account.id,
name: account.name,
externalTransferAllowed: account.externalTransferAllowed,
crossCurrencyAllowed: account.crossCurrencyAllowed,
productKindName: account.productKindName,
productTypeName: account.productTypeName,
bankAlias: account.bankAlias,
sourceId: account.sourceId,
visible: account.visible,
accountOpeningDate: account.accountOpeningDate,
lastUpdateDate: account.lastUpdateDate,
userPreferences: nil,//account.userPreferences,
state: nil,//account.state,
parentId: account.parentId,
subArrangements: nil,//account.subArrangements,
financialInstitutionId: account.financialInstitutionId,
lastSyncDate: account.lastSyncDate)
}
static func convert(_ accounts: ArrangementsClient2.CreditCardProductKinds) -> RetailAccountsAndTransactionsJourney.CreditCardProductKinds? {
return .init(products: accounts.products.map(Self.convert),
additions: accounts.additions,
name: accounts.name,
aggregatedBalance: accounts.aggregatedBalance != nil ? Self.convert(accounts.aggregatedBalance!) : nil)
}
// MARK: - Debit Card Converter
static func convert(_ account: ArrangementsClient2.DebitCard) -> RetailAccountsAndTransactionsJourney.DebitCard {
return .init(number: account.number,
urgentTransferAllowed: account.urgentTransferAllowed,
cardNumber: account.cardNumber,
accountInterestRate: account.accountInterestRate,
accountHolderNames: account.accountHolderNames,
debitCardsItems: [],//account.debitCardsItems,
startDate: account.startDate,
validThru: account.validThru,
additions: account.additions,
identifier: account.id,
name: account.name,
externalTransferAllowed: account.externalTransferAllowed,
crossCurrencyAllowed: account.crossCurrencyAllowed,
productKindName: account.productKindName,
productTypeName: account.productTypeName,
bankAlias: account.bankAlias,
sourceId: account.sourceId,
visible: account.visible,
accountOpeningDate: account.accountOpeningDate,
lastUpdateDate: account.lastUpdateDate,
userPreferences: nil,//account.userPreferences,
state: nil,//account.state,
parentId: account.parentId,
subArrangements: nil,//account.subArrangements,
financialInstitutionId: account.financialInstitutionId,
lastSyncDate: account.lastSyncDate)
}
static func convert(_ accounts: ArrangementsClient2.DebitCardProductKinds) -> RetailAccountsAndTransactionsJourney.DebitCardProductKinds? {
return .init(products: accounts.products.map(Self.convert),
additions: accounts.additions,
name: accounts.name,
aggregatedBalance: accounts.aggregatedBalance != nil ? Self.convert(accounts.aggregatedBalance!) : nil)
}
// MARK: - Investment Accounts Converter
static func convert(_ account: ArrangementsClient2.InvestmentAccount) -> RetailAccountsAndTransactionsJourney.InvestmentAccount {
return .init(currentInvestmentValue: account.currentInvestmentValue,
currency: account.currency,
urgentTransferAllowed: account.urgentTransferAllowed,
productNumber: account.productNumber,
iban: account.IBAN,
bban: account.BBAN,
additions: account.additions,
identifier: account.id,
name: account.name,
externalTransferAllowed: account.externalTransferAllowed,
crossCurrencyAllowed: account.crossCurrencyAllowed,
productKindName: account.productKindName,
productTypeName: account.productTypeName,
bankAlias: account.bankAlias,
sourceId: account.sourceId,
visible: account.visible,
accountOpeningDate: account.accountOpeningDate,
lastUpdateDate: account.lastUpdateDate,
userPreferences: nil,//account.userPreferences,
state: nil,//account.state,
parentId: account.parentId,
subArrangements: nil,//account.subArrangements,
financialInstitutionId: account.financialInstitutionId,
lastSyncDate: account.lastSyncDate)
}
static func convert(_ accounts: ArrangementsClient2.InvestmentAccountProductKinds) -> RetailAccountsAndTransactionsJourney.InvestmentAccountProductKinds? {
return .init(products: accounts.products.map(Self.convert),
additions: accounts.additions,
name: accounts.name,
aggregatedBalance: accounts.aggregatedBalance != nil ? Self.convert(accounts.aggregatedBalance!) : nil)
}
// MARK: - Base Converter Method
static func convert(_ summary: ArrangementsClient2.ProductSummary) -> RetailAccountsAndTransactionsJourney.ProductSummary {
let aggregatedBalance = summary.aggregatedBalance != nil ? Self.convert(summary.aggregatedBalance!) : nil
let currentAccounts = summary.currentAccounts != nil ? Self.convert(summary.currentAccounts!) : nil
let savingsAccounts = summary.savingsAccounts != nil ? Self.convert(summary.savingsAccounts!) : nil
let termDeposits = summary.termDeposits != nil ? Self.convert(summary.termDeposits!) : nil
let loans = summary.loans != nil ? Self.convert(summary.loans!) : nil
let creditCards = summary.creditCards != nil ? Self.convert(summary.creditCards!) : nil
let debitCards = summary.debitCards != nil ? Self.convert(summary.debitCards!) : nil
let investmentAccounts = summary.investmentAccounts != nil ? Self.convert(summary.investmentAccounts!) : nil
// let customProductKinds = summary.customProductKinds.map(CustomProductKind.init)
let additions = summary.additions
return RetailAccountsAndTransactionsJourney.ProductSummary.init(aggregatedBalance: aggregatedBalance,
currentAccounts: currentAccounts,
savingsAccounts: savingsAccounts,
termDeposits: termDeposits,
loans: loans,
creditCards: creditCards,
debitCards: debitCards,
investmentAccounts: investmentAccounts,
customProductKinds: summary.customProductKinds.map(CustomProductKind.init),
additions: additions)
// return .init(aggregatedBalance: aggregatedBalance,
// currentAccounts: currentAccounts,
// savingsAccounts: savingsAccounts,
// termDeposits: termDeposits,
// loans: loans,
// creditCards: creditCards,
// debitCards: debitCards,
// investmentAccounts: investmentAccounts,
// customProductKinds: summary.customProductKinds.map(CustomProductKind.init),
// additions: additions)
}
}
struct ErrorResponseConverter {
static func convert(_ errorResponse: ClientCommon.ErrorResponse) -> RetailAccountsAndTransactionsJourney.ErrorResponse {
switch errorResponse {
case let .error(code, data, error):
return .init(statusCode: code, data: data, error: error)
@unknown default:
fatalError()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment