package com.nhnkcp.mobilePaySample

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.nhnkcp.mobilePayLibrary.contants.PaymentCode
import com.nhnkcp.mobilePayLibrary.model.Payment

class PagerAdapter(activity: FragmentActivity,
    private val completion: (Payment) -> Unit
) : FragmentStateAdapter(activity) {

    private val fragment = linkedMapOf(
        "신용결제" to PaymentCode.PAYMENT_CARD_APPROVAL,
        "신용취소" to PaymentCode.PAYMENT_CARD_CANCEL,
        "현금결제" to PaymentCode.PAYMENT_CASH_APPROVAL,
        "현금취소" to PaymentCode.PAYMENT_CASH_CANCEL,
        "간편결제 승인" to PaymentCode.PAYMENT_EASY_PAY_APPROVAL,
        "간편결제 취소" to PaymentCode.PAYMENT_EASY_PAY_CANCEL,
        "간이영수증" to PaymentCode.PAYMENT_SIMPLE_RECEIPT,
        "영수증 이미지 전송" to PaymentCode.PAYMENT_SEND_RECEIPT,
        "영수증 출력" to PaymentCode.PAYMENT_PRINT_RECEIPT,
        "거래내역 보기" to PaymentCode.PAYMENT_HISTORY,
        "거래결과 요청" to PaymentCode.PAYMENT_RESULT,
    )

    override fun createFragment(position: Int): Fragment {
        val code = fragment.values.toList()[position]
        return InputFragment(code) { completion.invoke(it) }
    }

    override fun getItemCount(): Int = fragment.size

    fun getTabTitle(position: Int) = fragment.keys.toList()[position]
}