<commit_before>//
//  OneTapFlowViewModel.swift
//  MercadoPagoSDK
//
//  Created by <NAME> on 09/05/2018.
//  Copyright © 2018 MercadoPago. All rights reserved.
//

import Foundation

final internal class OneTapFlowModel: PXFlowModel {
    enum Steps: String {
        case finish
        case screenReviewOneTap
        case screenSecurityCode
        case serviceCreateESCCardToken
        case payment
    }

    var paymentData: PXPaymentData
    let checkoutPreference: PXCheckoutPreference
    var paymentOptionSelected: PaymentMethodOption
    let search: PXPaymentMethodSearch
    var readyToPay: Bool = false
    var paymentResult: PaymentResult?
    var instructionsInfo: PXInstructions?
    var businessResult: PXBusinessResult?
    var customerPaymentOptions: [CustomerPaymentMethod]?
    var paymentMethodPlugins: [PXPaymentMethodPlugin]?
    var splitAccountMoney: PXPaymentData?
    var disabledOption: PXDisabledOption?

    // Payment flow
    var paymentFlow: PXPaymentFlow?
    weak var paymentResultHandler: PXPaymentResultHandlerProtocol?

    var chargeRules: [PXPaymentTypeChargeRule]?

    var invalidESC: Bool = false

    // In order to ensure data updated create new instance for every usage
    internal var amountHelper: PXAmountHelper {
        get {
            return PXAmountHelper(preference: self.checkoutPreference, paymentData: self.paymentData, chargeRules: chargeRules, paymentConfigurationService: self.paymentConfigurationService, splitAccountMoney: splitAccountMoney)
        }
    }

    let escManager: MercadoPagoESC?
    let advancedConfiguration: PXAdvancedConfiguration
    let mercadoPagoServicesAdapter: MercadoPagoServicesAdapter
    let paymentConfigurationService: PXPaymentConfigurationServices

    init(paymentData: PXPaymentData, checkoutPreference: PXCheckoutPreference, search: PXPaymentMethodSearch, paymentOptionSelected: PaymentMethodOption, chargeRules: [PXPaymentTypeChargeRule]?, mercadoPagoServicesAdapter: MercadoPagoServicesAdapter, advancedConfiguration: PXAdvancedConfiguration, paymentConfigurationService: PXPaymentConfigurationServices, disabledOption: PXDisabledOption?, escManager: MercadoPagoESC?) {
        self.paymentData = paymentData.copy() as? PXPaymentData ?? paymentData
        self.checkoutPreference = checkoutPreference
        self.search = search
        self.paymentOptionSelected = paymentOptionSelected
        self.advancedConfiguration = advancedConfiguration
        self.chargeRules = chargeRules
        self.mercadoPagoServicesAdapter = mercadoPagoServicesAdapter
        self.escManager = escManager
        self.paymentConfigurationService = paymentConfigurationService
        self.disabledOption = disabledOption

        // Payer cost pre selection.
        if let firstCardID = search.expressCho?.first?.oneTapCard?.cardId, let payerCost = amountHelper.paymentConfigurationService.getSelectedPayerCostsForPaymentMethod(firstCardID) {
            updateCheckoutModel(payerCost: payerCost)
        }

        let paymentMethodId = search.expressCho?.first?.paymentMethodId
        let firstCardID = search.expressCho?.first?.oneTapCard?.cardId
        let creditsCase = paymentMethodId == PXPaymentTypes.CONSUMER_CREDITS.rawValue
        let cardCase = firstCardID != nil

        if cardCase || creditsCase {
            if let pmIdentifier = cardCase ? firstCardID : paymentMethodId,
                let payerCost = amountHelper.paymentConfigurationService.getSelectedPayerCostsForPaymentMethod(pmIdentifier) {
                updateCheckoutModel(payerCost: payerCost)
            }
        }
    }<commit_msg>remove first card exclusive logic<commit_after>//
//  OneTapFlowViewModel.swift
//  MercadoPagoSDK
//
//  Created by <NAME> on 09/05/2018.
//  Copyright © 2018 MercadoPago. All rights reserved.
//

import Foundation

final internal class OneTapFlowModel: PXFlowModel {
    enum Steps: String {
        case finish
        case screenReviewOneTap
        case screenSecurityCode
        case serviceCreateESCCardToken
        case payment
    }

    var paymentData: PXPaymentData
    let checkoutPreference: PXCheckoutPreference
    var paymentOptionSelected: PaymentMethodOption
    let search: PXPaymentMethodSearch
    var readyToPay: Bool = false
    var paymentResult: PaymentResult?
    var instructionsInfo: PXInstructions?
    var businessResult: PXBusinessResult?
    var customerPaymentOptions: [CustomerPaymentMethod]?
    var paymentMethodPlugins: [PXPaymentMethodPlugin]?
    var splitAccountMoney: PXPaymentData?
    var disabledOption: PXDisabledOption?

    // Payment flow
    var paymentFlow: PXPaymentFlow?
    weak var paymentResultHandler: PXPaymentResultHandlerProtocol?

    var chargeRules: [PXPaymentTypeChargeRule]?

    var invalidESC: Bool = false

    // In order to ensure data updated create new instance for every usage
    internal var amountHelper: PXAmountHelper {
        get {
            return PXAmountHelper(preference: self.checkoutPreference, paymentData: self.paymentData, chargeRules: chargeRules, paymentConfigurationService: self.paymentConfigurationService, splitAccountMoney: splitAccountMoney)
        }
    }

    let escManager: MercadoPagoESC?
    let advancedConfiguration: PXAdvancedConfiguration
    let mercadoPagoServicesAdapter: MercadoPagoServicesAdapter
    let paymentConfigurationService: PXPaymentConfigurationServices

    init(paymentData: PXPaymentData, checkoutPreference: PXCheckoutPreference, search: PXPaymentMethodSearch, paymentOptionSelected: PaymentMethodOption, chargeRules: [PXPaymentTypeChargeRule]?, mercadoPagoServicesAdapter: MercadoPagoServicesAdapter, advancedConfiguration: PXAdvancedConfiguration, paymentConfigurationService: PXPaymentConfigurationServices, disabledOption: PXDisabledOption?, escManager: MercadoPagoESC?) {
        self.paymentData = paymentData.copy() as? PXPaymentData ?? paymentData
        self.checkoutPreference = checkoutPreference
        self.search = search
        self.paymentOptionSelected = paymentOptionSelected
        self.advancedConfiguration = advancedConfiguration
        self.chargeRules = chargeRules
        self.mercadoPagoServicesAdapter = mercadoPagoServicesAdapter
        self.escManager = escManager
        self.paymentConfigurationService = paymentConfigurationService
        self.disabledOption = disabledOption

        // Payer cost pre selection.
        let paymentMethodId = search.expressCho?.first?.paymentMethodId
        let firstCardID = search.expressCho?.first?.oneTapCard?.cardId
        let creditsCase = paymentMethodId == PXPaymentTypes.CONSUMER_CREDITS.rawValue
        let cardCase = firstCardID != nil

        if cardCase || creditsCase {
            if let pmIdentifier = cardCase ? firstCardID : paymentMethodId,
                let payerCost = amountHelper.paymentConfigurationService.getSelectedPayerCostsForPaymentMethod(pmIdentifier) {
                updateCheckoutModel(payerCost: payerCost)
            }
        }
    }
{'fraction_non_alphanumeric': 0.05698371893744644, 'fraction_numerical': 0.003427592116538132, 'mean_word_length': 3.9074982480728804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '677762', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1741, 'n_words': 419}