<commit_before>//
//  MercadoPagoServicesModelAdapter.swift
//  MercadoPagoSDK
//
//  Created by <NAME> on 10/25/17.
//  Copyright © 2017 MercadoPago. All rights reserved.
//

import Foundation
import MercadoPagoServices

extension MercadoPagoServicesAdapter {

    open func getPXSiteFromId(_ siteId: String) -> PXSite {
        let currency = MercadoPagoContext.getCurrency()
        let pxCurrency = getPXCurrencyFromCurrency(currency)
        let pxSite = PXSite(id: siteId, currencyId: pxCurrency.id)
        return pxSite
    }

    open func getPXCurrencyFromCurrency(_ currency: Currency) -> PXCurrency {
        let id: String = currency._id
        let description: String = currency._description
        let symbol: String = currency.symbol
        let decimalPlaces: Int = currency.decimalPlaces
        let decimalSeparator: String = currency.decimalSeparator
        let thousandSeparator: String = currency.thousandsSeparator
        let pxCurrency = PXCurrency(id: id, description: description, symbol: symbol, decimalPlaces: decimalPlaces, decimalSeparator: decimalSeparator, thousandSeparator: thousandSeparator)
        return pxCurrency
    }

    open func getCurrencyFromPXCurrency(_ pxCurrency: PXCurrency?) -> Currency {
        if let pxCurrency = pxCurrency {
            let _id: String = pxCurrency.id
            let description: String = pxCurrency._description ?? ""
            let symbol: String = pxCurrency.symbol ?? "$"
            let decimalPlaces: Int = pxCurrency.decimalPlaces ?? 2
            let decimalSeparator: String = pxCurrency.decimalSeparator ?? ","
            let thousandSeparator: String = pxCurrency.thousandSeparator ?? "."
            let currency = Currency(_id: _id, description: description, symbol: symbol, decimalPlaces: decimalPlaces, decimalSeparator: decimalSeparator, thousandSeparator: thousandSeparator)
            return currency
        }
        return Currency()
    }

    open func getCheckoutPreferenceFromPXCheckoutPreference(_ pxCheckoutPreference: PXCheckoutPreference) -> CheckoutPreference {
        let checkoutPreference = CheckoutPreference()
        checkoutPreference._id = pxCheckoutPreference.id
        if let pxCheckoutPreferenceItems = pxCheckoutPreference.items {
            for pxItem in pxCheckoutPreferenceItems {
                let item = getItemFromPXItem(pxItem)
                checkoutPreference.items = Array.safeAppend(checkoutPreference.items, item)
            }
        }
        checkoutPreference.payer = getPayerFromPXPayer(pxCheckoutPreference.payer)
        checkoutPreference.paymentPreference = getPaymentPreferenceFromPXPaymentPreference(pxCheckoutPreference.paymentPreference)
        checkoutPreference.siteId = pxCheckoutPreference.siteId ?? ""
        checkoutPreference.expirationDateFrom = pxCheckoutPreference.expirationDateFrom ?? Date()
        checkoutPreference.expirationDateTo = pxCheckoutPreference.expirationDateTo ?? Date()
        return checkoutPreference
    }

    open func getItemFromPXItem(_ pxItem: PXItem) -> Item {
        let id: String = pxItem.id
        let title: String = pxItem.title ?? ""
        let quantity: Int = pxItem.quantity ?? 1
        let unitPrice: Double = pxItem.unitPrice ?? 0.0
        let description: String = pxItem._description ?? ""
        let currencyId: String = pxItem.currencyId ?? "ARS"
        let item = Item(_id: id, title: title, quantity: quantity, unitPrice: unitPrice, description: description, currencyId: currencyId)
        return item
    }

    open func getPaymentPreferenceFromPXPaymentPreference(_ pxPaymentPreference: PXPaymentPreference?) -> PaymentPreference {
        let paymentPreference = PaymentPreference()
        if let pxPaymentPreference = pxPaymentPreference {
            paymentPreference.excludedPaymentMethodIds = Set(pxPaymentPreference.excludedPaymentMethodIds ?? [])
            paymentPreference.excludedPaymentTypeIds = Set(pxPaymentPreference.excludedPaymentTypeIds ?? [])
            paymentPreference.defaultPaymentMethodId = pxPaymentPreference.defaultPaymentMethodId
            paymentPreference.maxAcceptedInstallments = pxPaymentPreference.maxAcceptedInstallments != nil ? pxPaymentPreference.maxAcceptedInstallments! : paymentPreference.maxAcceptedInstallments
            paymentPreference.defaultInstallments = pxPaymentPreference.defaultInstallments != nil ? pxPaymentPreference.defaultInstallments! : paymentPreference.defaultInstallments
            paymentPreference.defaultPaymentTypeId = pxPaymentPreference.defaultPaymentTypeId
        }
        return paymentPreference
    }

    open func getInstructionsInfoFromPXInstructions(_ pxInstructions: PXInstructions) -> InstructionsInfo {
        let instructionsInfo = InstructionsInfo()
        instructionsInfo.amountInfo = getAmountInfoFromPXAmountInfo(pxInstructions.amountInfo)

        if let pxInstructionsInstructions = pxInstructions.instructions {
            for pxInstruction in pxInstructionsInstructions {
                let instruction = getInstructionFromPXInstruction(pxInstruction)
                instructionsInfo.instructions = Array.safeAppend(instructionsInfo.instructions, instruction)
            }
        }

        return instructionsInfo
    }

    open func getInstructionFromPXInstruction(_ pxInstruction: PXInstruction) -> Instruction {
        let instruction = Instruction()
        instruction.title = pxInstruction.title ?? ""
        instruction.subtitle = pxInstruction.subtitle
        instruction.accreditationMessage = pxInstruction.accreditationMessage ?? ""
        instruction.accreditationComment = pxInstruction.accreditationComments

        if let pxInstructionReferences = pxInstruction.references {
            instruction.references = []
            for pxInstructionReference in pxInstructionReferences {
                let instructionReference = getInstructionReferenceFromPXInstructionReference(pxInstructionReference)
                instruction.references = Array.safeAppend(instruction.references, instructionReference)
            }
        }

        instruction.info = pxInstruction.info
        instruction.secondaryInfo = pxInstruction.secondaryInfo
        instruction.tertiaryInfo = pxInstruction.tertiaryInfo

        if let pxInstructionAction = pxInstruction.actions {
            for pxInstructionAction in pxInstructionAction {
                let instructionAction = getInstructionActionFromPXInstructionAction(pxInstructionAction)
                instruction.actions = Array.safeAppend(instruction.actions, instructionAction)
            }
        }

        instruction.type = pxInstruction.type ?? ""
        return instruction
    }

    open func getInstructionReferenceFromPXInstructionReference(_ pxInstructionReference: PXInstructionReference) -> InstructionReference {
        let instructionReference = InstructionReference()
        instructionReference.label = pxInstructionReference.label
        instructionReference.value = pxInstructionReference.fieldValue
        instructionReference.separator = pxInstructionReference.separator
        instructionReference.comment = pxInstructionReference.comment
        return instructionReference
    }<commit_msg>Minor fix<commit_after>//
//  MercadoPagoServicesModelAdapter.swift
//  MercadoPagoSDK
//
//  Created by <NAME> on 10/25/17.
//  Copyright © 2017 MercadoPago. All rights reserved.
//

import Foundation
import MercadoPagoServices

extension MercadoPagoServicesAdapter {

    open func getPXSiteFromId(_ siteId: String) -> PXSite {
        let currency = MercadoPagoContext.getCurrency()
        let pxCurrency = getPXCurrencyFromCurrency(currency)
        let pxSite = PXSite(id: siteId, currencyId: pxCurrency.id)
        return pxSite
    }

    open func getPXCurrencyFromCurrency(_ currency: Currency) -> PXCurrency {
        let id: String = currency._id
        let description: String = currency._description
        let symbol: String = currency.symbol
        let decimalPlaces: Int = currency.decimalPlaces
        let decimalSeparator: String = currency.decimalSeparator
        let thousandSeparator: String = currency.thousandsSeparator
        let pxCurrency = PXCurrency(id: id, description: description, symbol: symbol, decimalPlaces: decimalPlaces, decimalSeparator: decimalSeparator, thousandSeparator: thousandSeparator)
        return pxCurrency
    }

    open func getCurrencyFromPXCurrency(_ pxCurrency: PXCurrency?) -> Currency {
        if let pxCurrency = pxCurrency {
            let _id: String = pxCurrency.id
            let description: String = pxCurrency._description ?? ""
            let symbol: String = pxCurrency.symbol ?? "$"
            let decimalPlaces: Int = pxCurrency.decimalPlaces ?? 2
            let decimalSeparator: String = pxCurrency.decimalSeparator ?? ","
            let thousandSeparator: String = pxCurrency.thousandSeparator ?? "."
            let currency = Currency(_id: _id, description: description, symbol: symbol, decimalPlaces: decimalPlaces, decimalSeparator: decimalSeparator, thousandSeparator: thousandSeparator)
            return currency
        }
        return Currency()
    }

    open func getCheckoutPreferenceFromPXCheckoutPreference(_ pxCheckoutPreference: PXCheckoutPreference) -> CheckoutPreference {
        let checkoutPreference = CheckoutPreference()
        checkoutPreference._id = pxCheckoutPreference.id
        if let pxCheckoutPreferenceItems = pxCheckoutPreference.items {
            for pxItem in pxCheckoutPreferenceItems {
                let item = getItemFromPXItem(pxItem)
                checkoutPreference.items = Array.safeAppend(checkoutPreference.items, item)
            }
        }
        checkoutPreference.payer = getPayerFromPXPayer(pxCheckoutPreference.payer)
        checkoutPreference.paymentPreference = getPaymentPreferenceFromPXPaymentPreference(pxCheckoutPreference.paymentPreference)
        checkoutPreference.siteId = pxCheckoutPreference.siteId ?? ""
        checkoutPreference.expirationDateFrom = pxCheckoutPreference.expirationDateFrom ?? Date()
        checkoutPreference.expirationDateTo = pxCheckoutPreference.expirationDateTo ?? Date()
        return checkoutPreference
    }

    open func getItemFromPXItem(_ pxItem: PXItem) -> Item {
        let id: String = pxItem.id
        let title: String = pxItem.title ?? ""
        let quantity: Int = pxItem.quantity ?? 1
        let unitPrice: Double = pxItem.unitPrice ?? 0.0
        let description: String = pxItem._description ?? ""
        let currencyId: String = pxItem.currencyId ?? "ARS"
        let item = Item(_id: id, title: title, quantity: quantity, unitPrice: unitPrice, description: description, currencyId: currencyId)
        return item
    }

    open func getPaymentPreferenceFromPXPaymentPreference(_ pxPaymentPreference: PXPaymentPreference?) -> PaymentPreference {
        let paymentPreference = PaymentPreference()
        if let pxPaymentPreference = pxPaymentPreference {
            paymentPreference.excludedPaymentMethodIds = Set(pxPaymentPreference.excludedPaymentMethodIds ?? [])
            paymentPreference.excludedPaymentTypeIds = Set(pxPaymentPreference.excludedPaymentTypeIds ?? [])
            paymentPreference.defaultPaymentMethodId = pxPaymentPreference.defaultPaymentMethodId
            paymentPreference.maxAcceptedInstallments = pxPaymentPreference.maxAcceptedInstallments != nil ? pxPaymentPreference.maxAcceptedInstallments! : paymentPreference.maxAcceptedInstallments
            paymentPreference.defaultInstallments = pxPaymentPreference.defaultInstallments != nil ? pxPaymentPreference.defaultInstallments! : paymentPreference.defaultInstallments
            paymentPreference.defaultPaymentTypeId = pxPaymentPreference.defaultPaymentTypeId
        }
        return paymentPreference
    }

    open func getInstructionsInfoFromPXInstructions(_ pxInstructions: PXInstructions) -> InstructionsInfo {
        let instructionsInfo = InstructionsInfo()
        instructionsInfo.amountInfo = getAmountInfoFromPXAmountInfo(pxInstructions.amountInfo)

        if let pxInstructionsInstructions = pxInstructions.instructions {
            for pxInstruction in pxInstructionsInstructions {
                let instruction = getInstructionFromPXInstruction(pxInstruction)
                instructionsInfo.instructions = Array.safeAppend(instructionsInfo.instructions, instruction)
            }
        }

        return instructionsInfo
    }

    open func getInstructionFromPXInstruction(_ pxInstruction: PXInstruction) -> Instruction {
        let instruction = Instruction()
        instruction.title = pxInstruction.title ?? ""
        instruction.subtitle = pxInstruction.subtitle
        instruction.accreditationMessage = pxInstruction.accreditationMessage ?? ""
        instruction.accreditationComment = pxInstruction.accreditationComments

        if let pxInstructionReferences = pxInstruction.references {
            instruction.references = []
            for pxInstructionReference in pxInstructionReferences {
                let instructionReference = getInstructionReferenceFromPXInstructionReference(pxInstructionReference)
                instruction.references = Array.safeAppend(instruction.references, instructionReference)
            }
        }

        instruction.info = pxInstruction.info
        instruction.secondaryInfo = pxInstruction.secondaryInfo
        instruction.tertiaryInfo = pxInstruction.tertiaryInfo

        if let pxInstructionAction = pxInstruction.action {
            for pxInstructionAction in pxInstructionAction {
                let instructionAction = getInstructionActionFromPXInstructionAction(pxInstructionAction)
                instruction.actions = Array.safeAppend(instruction.actions, instructionAction)
            }
        }

        instruction.type = pxInstruction.type ?? ""
        return instruction
    }

    open func getInstructionReferenceFromPXInstructionReference(_ pxInstructionReference: PXInstructionReference) -> InstructionReference {
        let instructionReference = InstructionReference()
        instructionReference.label = pxInstructionReference.label
        instructionReference.value = pxInstructionReference.fieldValue
        instructionReference.separator = pxInstructionReference.separator
        instructionReference.comment = pxInstructionReference.comment
        return instructionReference
    }
{'fraction_non_alphanumeric': 0.0639933513401205, 'fraction_numerical': 0.0019391924648521366, 'mean_word_length': 3.4078144078144077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '375336', 'n_tokens_mistral': 3469, 'n_tokens_neox': 3645, 'n_words': 727}