package cn.yyxx.commsdk.impl;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;

import java.util.List;

import cn.yyxx.commsdk.base.entity.SdkChargeInfo;
import cn.yyxx.commsdk.base.entity.SdkRoleInfo;
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.IRoleData;

/**
 * @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, Boolean isLandscape, ICallback callback) {
        impl.initialize(activity, isLandscape, callback);
    }

    public void onFloatCenterLogout(Activity activity, ICallback callback) {
    }

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

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

    public void charge(Activity activity, SdkChargeInfo chargeInfo, ICallback callback) {
        impl.charge(activity, chargeInfo, callback);
    }

    public void roleCreate(Activity activity, SdkRoleInfo roleInfo, ICallback callback) {
        if (impl instanceof IRoleData) {
            ((IRoleData) impl).roleCreate(activity, roleInfo, callback);
        }
    }

    public void roleLauncher(Activity activity, SdkRoleInfo roleInfo, ICallback callback) {
        if (impl instanceof IRoleData) {
            ((IRoleData) impl).roleLauncher(activity, roleInfo, callback);
        }
    }

    public void roleUpgrade(Activity activity, SdkRoleInfo roleInfo, ICallback callback) {
        if (impl instanceof IRoleData) {
            ((IRoleData) impl).roleUpgrade(activity, roleInfo, callback);
        }
    }

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

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

    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) {
        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 requestPermission(Activity activity, List<String> permissions, ICallback callback) {
    }
}
