package com.yidianling.dynamic.router

import android.app.Activity
import android.content.Intent
import android.support.v4.app.DialogFragment
import android.support.v7.app.AppCompatActivity
import com.ydl.ydlcommon.actions.imagepicker.PickerCallback
import com.ydl.ydlcommon.actions.imagepicker.YdlImagePicker
import com.ydl.ydlcommon.base.config.HttpConfig
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.yidianling.router.RouterManager
import com.yidianling.user.api.bean.UserResponseBean
import com.yidianling.user.api.service.IUserService

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

//    fun getImService(): IMServiceImpl {
//        return ModularServiceManager.provide(IMServiceImpl::class.java)
//    }

    fun getUserService(): IUserService {
        return ModularServiceManager.provide(IUserService::class.java)
    }

    /**
     * 获取专家主页url
     */
    fun getExpertHost(): String {
        return  HttpConfig.H5_URL + "experts/"
    }

    fun getShareExpertHost(): String {
        return  HttpConfig.MH5_URL+ "experts/"
    }

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

    fun getUserInfo(): UserResponseBean.UserInfo? = getUserService().getUserInfo()

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

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

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

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

    fun expertSearchIntent(activity: Activity, category: Int, showType: Int, isInitShowHot: Boolean): Intent? {
        return RouterManager.getConsultantRouter()?.expertSearchIntent(activity, category, showType, isInitShowHot)
    }

    fun testResultIntent(activity: Activity, testResultId: Int): Intent? {
        return RouterManager.getTestsRouter()?.testResultIntent(activity, testResultId)
    }

    fun testDetailIntent(activity: Activity, testId: Int): Intent? {
        return RouterManager.getTestsRouter()?.testDetailIntent(activity, testId)
    }

    fun testResultH5(testResultId: Int){
        RouterManager.getTestsRouter()!!.testH5Result(testResultId.toString())
    }

    fun testDetailH5(testId: Int){
        RouterManager.getTestsRouter()?.testDetailH5(testId.toString());
    }

    fun phoneCallIntent(activity: Activity): Intent? {
        return RouterManager.getPhoneCallRouter()?.phoneCallIntent(activity)
    }

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

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

    fun testAnswerIntent(activity: Activity): Intent? {
        return RouterManager.getTestsRouter()?.testAnswerIntent(activity)
    }


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

    fun phoneCallFragment(head: String, callId: String): DialogFragment? {
        return RouterManager.getPhoneCallRouter()?.phoneCallFragment(head, callId)
    }


    fun startChat(activity: AppCompatActivity, toUid: String) {
        RouterManager.getImRouter().startP2PSession(activity, toUid)
    }

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

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

    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 showSelector(activity: Activity, requestCode: Int) {
        RouterManager.getImRouter().showSelector(activity, requestCode)
    }

    fun startPicker(activity: AppCompatActivity, openCamera: Boolean, callback: PickerCallback) {
        YdlImagePicker.startPicker(activity, openCamera, callback)
    }

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