package com.develop.food.base.utils

import android.os.Bundle
import com.develop.food.base.repo.FoodDataProvider
import com.develop.food.base.router.Screens
import com.develop.food.base.router.navigateTo
import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevModes
import com.kuyuntech.cofarcooking.device.sdk.constant.core.WorkModes
import com.kuyuntech.cofarcooking.device.sdk.util.core.CofarSDK

object  CommonUtils {

    fun navigateToRemoteRecipe(number:String){


        FoodDataProvider.getDatabase().recipeDao().apply {
            var recipeNumber = number
            if (recipeNumber.contains("@")) {
                var (numbers, language) = recipeNumber.split("@")
                recipeNumber = numbers
            }

            val recipeBean = queryRecipe(recipeNumber)
            if (recipeBean != null) {

                TopResumedActivityHolder.getCurrentActivity()?.navigateTo(Screens.Cook.COOK_DETAIL) {



                    withString(
                        SOURCE_TAG,  "local"

                    )
                    withString(NUMBER_TAG, number)

                }

            }else{

                TopResumedActivityHolder.getCurrentActivity()?.navigateTo(Screens.Cook.COOK_DETAIL) {
                    withString(SOURCE_TAG,  "remote")
                    withString(NUMBER_TAG, number)

                }

            }

        }



    }


    fun navigateToAdaptedCooking(){


        TopResumedActivityHolder.getCurrentActivity()?.apply {


            if(localClassName.indexOf("ModesDetailActivity") != -1){
                if(CommonUtils.devReady()){
                    return
                }else{
                    finish()
                }
            }

        }





        if(DevModes.SOUP == CofarSDK.devInfo().devMode){
            val bundle = Bundle()
            bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
            bundle.putString("OP_MODE","APP")
            TopResumedActivityHolder.getCurrentActivity()?.navigateTo(Screens.Cook.COOK_MODES) {
                with(bundle)
            }
        }else if (DevModes.AIR_FRYER == CofarSDK.devInfo().devMode){
            val bundle = Bundle()
            bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
            bundle.putString("OP_MODE","APP")
            TopResumedActivityHolder.getCurrentActivity()?.navigateTo(Screens.Cook.COOK_MODES) {
                with(bundle)
            }
        }



    }

    fun devReady():Boolean{

        var result = false;
        if(DevModes.SOUP == CofarSDK.devInfo().devMode){
            result  =TopResumedActivityHolder.getCurrentActivity()?.localClassName?.indexOf("ModesDetailActivity") != -1  && CofarSDK.devInfo().mode.mode === WorkModes.ADAPTED_COOKING && !CofarSDK.devInfo().isWeightStatus

        }else if (DevModes.AIR_FRYER == CofarSDK.devInfo().devMode){
            result  =TopResumedAtyHolder.getCurrentActivity()?.localClassName?.indexOf("ModesDetailActivity") != -1  && CofarSDK.devInfo().mode.mode === WorkModes.AF_DIY  && !CofarSDK.devInfo().isWeightStatus

        }

        return result





    }



}