package com.yidianling.ydlcommon.custom.router

import android.app.Activity
import android.app.Application
import android.support.annotation.StringRes
import android.support.v7.app.AppCompatActivity
import com.yidianling.ydlcommon.core.base.BaseApplication
import com.yidianling.ydlcommon.custom.GlobalInfo
import com.yidianling.ydlcommon.custom.constant.YdlConstants
import com.yidianling.ydlcommon.custom.data.YdlDataManager
import com.yidianling.ydlcommon.custom.imagepicker.PickerCallback
import com.yidianling.ydlcommon.custom.imagepicker.YdlImagePicker
import com.yidianling.ydlcommon.custom.pay.PayActivity
import com.yidianling.ydlcommon.custom.pay.PayParams
import com.yidianling.ydlcommon.custom.pay.redpacket.jump.JumpPayActivity
import com.yidianling.ydlcommon.custom.remind.ToastHelper

/**
 * author : Zhangwenchao
 * e-mail : zhangwch@yidianling.com
 * time   : 2018/04/24
 *
 *  项目通用模块对外提供的方法
 */
class YdlCommonOut {

    companion object {
        const val HOLDER_PARAM = YdlConstants.HOLDER_PARAM
        const val BUNDLE = YdlConstants.BUNDLE

        const val API_HOST = YdlConstants.API_HOST
        var API_HOST_H5 = YdlConstants.API_HOST_H5
        var API_HOST_WEB = YdlConstants.API_HOST_WEB
        const val SHAREZJ = YdlConstants.SHAREZJ
        const val BIND_PHONE_ACTION = YdlConstants.BIND_PHONE_ACTION
        const val HELP_URL = YdlConstants.HELP_URL
        var ZJZHUYE = YdlConstants.ZJZHUYE
        const val SILENCED_CODE = YdlConstants.SILENCED_CODE
        var YUYDETAIL = YdlConstants.YUYDETAIL
        const val PUBLISH_TYPE = YdlConstants.PUBLISH_TYPE

        fun showToast(content: String) {
            ToastHelper.show(content)
        }

        fun showToast(@StringRes stringId: Int) {
            ToastHelper.show(stringId)
        }

        fun getApp(): Application {
            return BaseApplication.getApp()
        }

        //打开支付跳转中间页
        fun startJumpPayActivity(activity: Activity, payParams: PayParams, requestCode: Int){
            activity.startActivityForResult(JumpPayActivity.newIntent(activity,payParams),requestCode)
            activity.overridePendingTransition(0, 0)
        }

        // 打开支付页面
        fun startPayActivity(activity: Activity, payParams: PayParams, requestCode: Int) {
            activity.startActivityForResult(PayActivity.newIntent(activity, payParams), requestCode)
        }

        // 是否开启了声音
        fun isVoice(): Boolean = YdlDataManager.getLocal().isVoice()

        fun putVoice(voice: Boolean) {
            YdlDataManager.getLocal().putVoice(voice)
        }

        // 是否开启了震动
        fun isShake(): Boolean = YdlDataManager.getLocal().isShake()

        fun putShake(shake: Boolean) {
            YdlDataManager.getLocal().putShake(shake)
        }

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

        fun setGlobalInfo(globalInfo: GlobalInfo) {
            YdlDataManager.getRam().setGlobalInfo(globalInfo)
        }

        fun putNewYearKeyword(key: String, value: GlobalInfo.GlobalData.NewYearKeyword?) {
            YdlDataManager.getRam().putNewYearKeyword(key, value)
        }

        fun getNewYearKeyword(key: String): GlobalInfo.GlobalData.NewYearKeyword? {
            return YdlDataManager.getRam().getNewYearKeyword(key)
        }

        fun getNewYearKeyWordByContent(content: String?): GlobalInfo.GlobalData.NewYearKeyword? {
            return YdlDataManager.getRam().getGlobalInfo()?.info?.getNewYearKeyWordByContent(content)
        }

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

        fun getChannelName(): String {
            return YdlDataManager.getRam().getChannelName()
        }
    }
}