package com.base.scanqrclear.bean

import com.base.scanqrclear.bean.FunctionUIBean.Companion.KEY_YOUTUBE

data class YoutubeUIBean(
    val v: String? = null,//URL/VIDEO ID
    val channel: String? = null
) : ScanBean(KEY_YOUTUBE) {

    companion object {
        fun isYoutubeUIBeanQR(qrCodeValue: String): Boolean {
            return qrCodeValue.startsWith("https://www.youtube.com")
        }

        fun createYoutubeUIBean(qrCodeValue: String): YoutubeUIBean {

            var v: String? = null
            var channel: String? = null

            if (qrCodeValue.contains("watch")) {
                v = qrCodeValue.substring("https://www.youtube.com/watch?v=".length, qrCodeValue.length)
            }
            if (qrCodeValue.contains("channel")) {
                channel = qrCodeValue.substring("https://www.youtube.com/channel/".length, qrCodeValue.length)
            }

            return YoutubeUIBean(v, channel)
        }

        //    https://www.youtube.com/watch?v=www.yokutube.koko
        //    https://www.youtube.com/channel/56789
        fun YoutubeUIBean.createYoutubeQrString(): String {
            if (v != null) {
                return "https://www.youtube.com/watch?v=$v"
            }
            if (channel != null) {
                return "https://www.youtube.com/channel/$channel"
            }
            return ""
        }
    }
}