package com.example.stage_app.viewmodel

import android.content.Intent
import androidx.activity.result.ActivityResult
import androidx.lifecycle.ViewModel
import com.example.core.domain.AppConfig
import com.example.core.domain.PaymentResult
import com.example.core.domain.Printer
import com.example.core.domain.PspService
import com.example.core.model.PaymentResultEntity
import com.example.core.model.PrintEntity
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class StageViewModel @Inject constructor(
    private val pspService: PspService,
    private val paymentResult: PaymentResult,
    private val printer: Printer,
    private val appConfig: AppConfig
) : ViewModel() {


    fun postPaymentResult(paymentResultEntity: PaymentResultEntity?): String {
        return paymentResult.post(paymentResultEntity)
    }

    fun pay(amount: Long): Intent = pspService.pay(amount)

    fun paymentResult(
        id: String?,
        activityResult: ActivityResult
    ): PaymentResultEntity? {
        return pspService.decodePosResponse(
            id = id,
            activityResult = activityResult
        )
    }

    private val mock = listOf<PrintEntity>(

        PrintEntity(
            title = "اطلاعات مشتری",
            items = listOf(
                PrintEntity.ItemEntity("نام مشتری", "علی رضایی"),
                PrintEntity.ItemEntity("شماره تماس", "09123456789"),
                PrintEntity.ItemEntity("آدرس", "تهران، خیابان ولیعصر، پلاک ۱۲۳")
            ),
            type = PrintEntity.Type.CARD
        ),
        PrintEntity(
            title = "اطلاعات پرداخت",
            items = listOf(
                PrintEntity.ItemEntity("روش پرداخت", "کارت به کارت"),
                PrintEntity.ItemEntity("شماره پیگیری", "7845129630"),
                PrintEntity.ItemEntity("تاریخ", "1405/02/14")
            ),
            type = PrintEntity.Type.CARD
        ),
    )

    fun print(printEntities: List<PrintEntity>) {
        printer.print(
            printEntities = printEntities,
            icon = android.R.drawable.btn_star
        )
    }

    fun sendAndroidId(id: String) {
        appConfig.androidId(id)
    }
}
