package uz.myid.sdk.sample

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import uz.myid.android.sdk.capture.*

class ExampleKotlinActivity : AppCompatActivity(), MyIdResultListener {

    private val client: 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 externalId = "external_id"

        val myIdConfig = MyIdConfig.builder(clientId)
            .withPassportData(passportData)
            .withBirthDate(dateOfBirth)
            .withExternalId(externalId)
            .withEntryType(MyIdEntryType.AUTH)
            .withBuildMode(MyIdBuildMode.PRODUCTION)
            .withLocale(MyIdLocale.EN)
            .withPhoto(false)
            .build()

        val intent = client.createIntent(this, myIdConfig)
        result.launch(intent)
    }

    private val result = takeUserResult(this)
}