package com.wd.workoffice.ui.activity.login;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wd.workoffice.R;
import com.wd.workoffice.app.WorkApp;
import com.wd.workoffice.app.WorkBaseActivity;
import com.wd.workoffice.bean.workEnum.BatLoginType;
import com.wd.workoffice.retrofit.ApiService;
import com.wd.workoffice.util.DataKeeper;
import com.wd.workoffice.util.UserKeeper;
import com.wd.workoffice.util.WorkUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import flexible.xd.android_base.network.rtfhttp.RtfHelper;
import okhttp3.Request;

/**
 * 选择角色
 * author : flexible
 * email : lgd19940421@163.com
 * github: https://github.com/FlexibleXd
 **/
public class BatTypeActivity extends WorkBaseActivity {


    @BindView(R.id.tv_first)
    TextView tvFirst;
    @BindView(R.id.tv_second)
    TextView tvSecond;
    @BindView(R.id.activity_main)
    LinearLayout activityMain;

    @Override
    protected void initView() {
        ButterKnife.bind(this);
    }

    @Override
    protected void initData() {
    }


    @Override
    protected void initEvent() {
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_main_login_type;
    }



    @OnClick({R.id.tv_first, R.id.tv_second})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_first:
                DataKeeper.getInstance().keepBatLoginType(BatLoginType.GK.getCode());
                RtfHelper.getInstance().init(WorkUtils.getDomain(), chain -> {
                    Request original = chain.request();
                    Request request = original.newBuilder()
                            .header("Authorization", "Bearer " + UserKeeper.getInstance().getToken())
                            .header("userId", UserKeeper.getInstance().getUserId())
                            .method(original.method(), original.body())
                            .build();

                    return chain.proceed(request);
                });
                startActivity(LoginActivity.class);
                break;
            case R.id.tv_second:
                DataKeeper.getInstance().keepBatLoginType(BatLoginType.GT.getCode());
                RtfHelper.getInstance().init(WorkUtils.getDomain(), chain -> {
                    Request original = chain.request();
                    Request request = original.newBuilder()
                            .header("Authorization", "Bearer " + UserKeeper.getInstance().getToken())
                            .header("userId", UserKeeper.getInstance().getUserId())
                            .method(original.method(), original.body())
                            .build();

                    return chain.proceed(request);
                });
                startActivity(LoginActivity.class);
                break;

        }
    }
}
