package com.medical.ydl.medical.modular

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.alibaba.android.arouter.launcher.ARouter
import com.ydl.ydlcommon.bean.GlobalInfo
import com.ydl.ydlcommon.data.PlatformDataManager
import com.ydl.ydlcommon.data.http.GsonProvider
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.yidianling.im.api.bean.ReceiveRedPacketParam
import com.yidianling.im.api.service.IImService
import com.yidianling.user.api.bean.UserResponseBean
import com.yidianling.user.api.service.IAppService
import com.yidianling.user.api.service.IUserService

/**
 * 功能输入接口
 * 暴漏给app模块使用
 * Created by hgw on 2018/3/19.
 */
object MedicalPayIn {

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

    fun getAppService(): IAppService {
        return ModularServiceManager.provide(IAppService::class.java)
    }

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

    /**
     * 是否登录
     */
    fun isLogin(activity: Context, flag: Boolean): Boolean {
        if (!isLogin() && flag) {
            getUserService().loginByOneKeyLogin(activity, true)
            return false
        } else {
            return true
        }
    }


    fun myRedPockIntent(activity: Activity) {
        getAppService().myRedPockIntent(activity)
    }


    fun sendRedPacketIntent(activity: Activity, toUid: String, code: Int) {
        ARouter.getInstance().build("/user/sendRedPacket").withString("to_uid", toUid)
            .navigation(activity, code)
    }


    fun receiveRedPacketIntent(activity: Activity, param: ReceiveRedPacketParam) {
        getAppService().receiverRedPacketIntent(activity, GsonProvider.getGson().toJson(param))
    }


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


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

    fun getUserInfo(): UserResponseBean.UserInfo? {
        return getUserService().getUserInfo()
    }

    fun getUserResponse(): UserResponseBean? {
        return getUserService().getUserResponse()
    }

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

    fun loginWayIntent(context: Context): Intent? {
        return getUserService().loginWayIntent(context)
    }

    fun mainIntent(context: Context, selectTab: Int) {
        getAppService().mainIntent(context, selectTab, false)
    }

    fun mainIntentMessage(context: Context, docotrUid: String) {

        val bundle = Bundle()
        bundle.putInt("selectTab", 2)
        bundle.putString("docotrUid", docotrUid)

        ARouter.getInstance().build("/main/main")
            .withBundle("bundle", bundle)
            .navigation()
    }


    fun feedBackIntent(activity: Activity) {
        getAppService().feedBackIntent(activity)
    }

    fun getGlobalInfo(): GlobalInfo? {
        return PlatformDataManager.getRam().getGlobalInfo()
    }

}
