package edu.byu.suite.features.myFinancialCenter.controller

import android.content.Intent
import edu.byu.suite.features.myFinancialCenter.service.MfcClient
import edu.byu.support.payment.controller.PaymentAccountsActivity
import edu.byu.support.payment.controller.PaymentReviewActivity
import edu.byu.support.payment.model.PaymentAccount
import retrofit2.Response

/**
 * Created by geogor37 on 2/16/18
 */
class MfcPaymentAccountsActivity: PaymentAccountsActivity() {
	override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
		if (requestCode == UnpaidChargesFragment.CHECKOUT_REQUEST) {
			setResult(resultCode)
			finish()
		}
		super.onActivityResult(requestCode, resultCode, data)
	}

	override fun loadPaymentMethods() {
		enqueueCall(MfcClient().getApi(this).getPaymentTypes(), object: PaymentAccountsCallback<List<PaymentAccount>>(this, pathToReadableError = MfcClient.PATH_TO_READABLE_ERROR) {
			override fun parseResponse(response: Response<List<PaymentAccount>>?): List<PaymentAccount>? {
				return response?.body()
			}
		})
	}

	override fun continuePaymentProcess(selectedPaymentAccount: PaymentAccount) {
		startActivityForResult(Intent(this, MfcPaymentReviewActivity::class.java)
				.putExtra(PaymentReviewActivity.PAYMENT_ACCOUNT_TAG, selectedPaymentAccount)
				.putExtras(intent), UnpaidChargesFragment.CHECKOUT_REQUEST)
	}
}