package cn.yyxx.commsdk.impl;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;



import cn.yyxx.commsdk.base.entity.SdkChargeInfo;

import cn.yyxx.commsdk.base.entity.SdkOrderInfo;
import cn.yyxx.commsdk.base.entity.SdkRoleInfo;
import cn.yyxx.commsdk.base.entity.bean.InitBean;
import cn.yyxx.commsdk.base.internal.ICallback;
import cn.yyxx.commsdk.base.internal.feature.IApplication;
import cn.yyxx.commsdk.base.internal.feature.IFeature;
import cn.yyxx.commsdk.base.internal.feature.ILifeCycle;
import cn.yyxx.commsdk.base.internal.feature.IOrder;


/**
 * @author #Suyghur.
 * Created on 2021/12/25
 */
public class ChannelSdkImpl {

    private IFeature impl;
    private int channelId = 1;

    public ChannelSdkImpl(Context context) {
        //TODO 从配置文件读取channelId
        impl = ChannelSdkGenerator.getChannelInstance(context, channelId);
    }

    public void attachBaseContext(Application application, Context context) {
        if (impl instanceof IApplication) {
            ((IApplication) impl).attachBaseContext(application, context);
        }
    }

    public void initApplication(Application application) {
        if (impl instanceof IApplication) {
            ((IApplication) impl).initApplication(application);
        }
    }

    public void initialize(Activity activity, ICallback callback) {
        impl.initialize(activity, callback);
    }

    public void initializeSuccess(){
        impl.initializeSuccess();

    }
    public void setLogoutListener(Activity activity,ICallback callback){
        impl.setLogoutListener(activity,callback);
    }

    public void login(Activity activity, InitBean initBean, final ICallback callback) {
        impl.login(activity,initBean, callback);
    }

    public void logout() {
        impl.logout();
    }

    public void startPay(Activity activity, SdkOrderInfo sdkOrderInfo, ICallback callback) {
        if (impl instanceof IOrder) {
            ((IOrder) impl).startPay(activity,sdkOrderInfo,callback);
        }
    }

    public void uploadRoleInfo(Activity activity, String type, SdkRoleInfo roleInfo){
        impl.uploadRoleInfo(activity,type,roleInfo);
    };

    public boolean hasExitView(Activity activity) {
        return impl.hasExitView(activity);
    }

    public String getChannelOrderExt(){
        if (impl instanceof IOrder) {
            return ((IOrder) impl).getChannelOrderExt();
        }
        return "";
     }

    public void openExitView(Activity activity, final ICallback callback) {
        impl.openExitView(activity, callback);
    }

    public void onCreate(Activity activity, Bundle savedInstanceState){

        if (impl instanceof ILifeCycle) {
            ((ILifeCycle) impl).onCreate(activity,savedInstanceState);
        }
    }

    public void onStart(Activity activity) {
        if (impl instanceof ILifeCycle) {
            ((ILifeCycle) impl).onStart(activity);
        }
    }

    public void onRestart(Activity activity) {
        if (impl instanceof ILifeCycle) {
            ((ILifeCycle) impl).onReStart(activity);
        }
    }

    public void onResume(Activity activity) {
        if (impl instanceof ILifeCycle) {
            ((ILifeCycle) impl).onResume(activity);
        }
    }


    public void onPause(Activity activity) {
        if (impl instanceof ILifeCycle) {
            ((ILifeCycle) impl).onPause(activity);
        }
    }

    public void onStop(Activity activity) {
        if (impl instanceof ILifeCycle) {
            ((ILifeCycle) impl).onStop(activity);
        }
    }

    public void onDestroy(Activity activity) {

        if (impl instanceof ILifeCycle) {
            ((ILifeCycle) impl).onDestroy(activity);
        }

    }

    public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
        if (impl instanceof ILifeCycle) {
            ((ILifeCycle) impl).onActivityResult(activity, requestCode, resultCode, data);
        }
    }

    public void onNewIntent(Activity activity, Intent intent) {
        if (impl instanceof ILifeCycle) {
            ((ILifeCycle) impl).onNewIntent(activity, intent);
        }
    }

    public void onWindowFocusChanged(Activity activity,boolean hasFocus){
        if (impl instanceof ILifeCycle) {
            ((ILifeCycle) impl).onWindowFocusChanged(activity,hasFocus);
        }
    }
    public void onConfigurationChaged(Activity activity, Configuration newConfig){
        if (impl instanceof ILifeCycle) {
            ((ILifeCycle) impl).onConfigurationChanged(activity,newConfig);
        }
    }

}
