package uz.myid.sdk.sample

import android.os.Bundle
import androidx.fragment.app.Fragment
import uz.myid.android.sdk.capture.*
import uz.myid.android.sdk.capture.model.OrganizationDetails
import java.util.*

class ExampleKotlinFragment : Fragment(), MyIdResultListener {

    private val myIdClient = MyIdClient()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        startMyId()
    }

    override fun onSuccess(result: MyIdResult) {
        // Get face bitmap and result code
    }

    override fun onError(e: MyIdException) {
        // Get error message and code
    }

    override fun onUserExited() {
        // User exited sdk
    }

    private fun startMyId() {
        val clientId = "client_id"
        val passportData = "passport_data"
        val dateOfBirth = "date_of_birth"
        val sdkHash = "sdk_hash"
        val externalId = "external_id"
        val threshold = 0.50f

        val organizationDetails = OrganizationDetails(
            phoneNumber = "1234567",
        )

        val myIdConfig = MyIdConfig.Builder(clientId)
            .withPassportData(passportData)
            .withBirthDate(dateOfBirth)
            .withSdkHash(sdkHash)
            .withExternalId(externalId)
            .withThreshold(threshold)
            .withBuildMode(MyIdBuildMode.PRODUCTION)
            .withEntryType(MyIdEntryType.AUTH)
            .withResidency(MyIdResidentType.RESIDENT)
            .withLocale(Locale("en"))
            .withCameraShape(MyIdCameraShape.CIRCLE)
            .withOrganizationDetails(organizationDetails)
            .withPhoto(false)
            .build()

        val intent = myIdClient.createIntent(requireActivity(), myIdConfig)
        result.launch(intent)
    }

    private val result = takeUserResult(this)
}