package com.ydl.confide.router

import android.app.Activity
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import com.yidianling.router.RouterManager
import com.yidianling.router.user.UserResponse

/**
 * author : Zhangwenchao
 * e-mail : zhangwch@yidianling.com
 * time   : 2018/04/25
 */
object PhoneCallIn {

    fun isLogin(): Boolean {
        return RouterManager.getUserRouter()?.isLogin()?:false
    }

    fun getUserInfo(): UserResponse.UserInfo? = RouterManager.getUserRouter()?.getUserInfo()

    fun rechargeIntent(activity: Activity): Intent? {
        return RouterManager.getAppRouter()?.rechargeIntent(activity)
    }

    fun inputPhoneIntent(activity: Activity, smsAction: String): Intent? {
        return RouterManager.getUserRouter()?.inputPhoneIntent(activity, smsAction)
    }

    fun loginWayIntent(activity: Activity): Intent? {
        return RouterManager.getUserRouter()?.loginWayIntent(activity)
    }

    fun publishTrendIntent(activity: Activity, url: String, cover: String, title: String): Intent? {
        return RouterManager.getDynamicRouter()?.publishTrendIntent(activity, url, cover, title)
    }

    fun myRedPacketIntent(activity: Activity): Intent? {
        return RouterManager.getAppRouter()?.myRedPockIntent(activity)
    }

    fun fmDetailIntent(activity: Activity, fmId: Int): Intent? {
        return RouterManager.getFMRouter()?.fmDetailIntent(activity, fmId)
    }

    fun isFmPlaying(): Boolean {
        return RouterManager.getFMRouter()?.isPlaying() ?: false
    }

    fun isCoursePlaying(): Boolean {
        return RouterManager.getCourseRouter()?.isPlaying() ?: false
    }

    fun getFmId(): Int {
        return RouterManager.getFMRouter()?.getFmId() ?: 0
    }

    /**
     * 课程播放页
     */
    fun startCoursePlayPage(activity: Activity){
        RouterManager.getCourseRouter()?.startCoursePlayPage(activity,1)
    }

    fun playCourse(){
        if (!isCoursePlaying()){
            RouterManager.getCourseRouter()?.play()
        }
    }

    fun pauseCourse(){
        if (isCoursePlaying()){
            RouterManager.getCourseRouter()?.pause()
        }
    }

    fun rePlayFM(){
        RouterManager.getFMRouter()?.replay()
    }

    fun pauseFm(){
        RouterManager.getFMRouter()?.pause()
    }

    /**
     * 私聊
     */
    fun startChat(context: AppCompatActivity, toUid: String, flag: Int, canTalk: Int) {
        RouterManager.getImRouter().startChat(context,toUid,flag,canTalk)
    }
}