package com.adealink.weparty.commonui.mediapicker.videoselect

import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.ActivityResultRegistry
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner

abstract class SelectVideoLifecycleObserver(
    private val registry: ActivityResultRegistry,
    private val registerKey: String = "SelectVideo"
) :
    DefaultLifecycleObserver {
    lateinit var launcher: ActivityResultLauncher<VideoSelectRequest>

    override fun onCreate(owner: LifecycleOwner) {
        launcher = registry.register(registerKey, owner, VideoSelectContract()) {
            onResult(it.source, it.resultCode, it.path, it.uri)
        }
    }

    fun launch(source: String = "") {
        launcher.launch(VideoSelectRequest(1, source))
    }

    abstract fun onResult(source: String, resultCode: Int, path: String?, uri: String?)
}