package com.wisewoods.eduandroid.ui;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.wisewoods.base.app.UserManager;
import com.wisewoods.base.bean.ProjectList;
import com.wisewoods.base.bean.Role;
import com.wisewoods.base.net.JCallback;
import com.wisewoods.base.page.BaseListActivity;
import com.wisewoods.eduandroid.R;
import com.wisewoods.eduandroid.app.App;
import com.wisewoods.eduandroid.databinding.ActivityProjectBinding;
import com.wisewoods.eduandroid.ui.adapter.ProjectAdapter;

import retrofit2.Call;
import retrofit2.Response;

public class ProjectActivity extends BaseListActivity<ActivityProjectBinding> {

    private ProjectAdapter projectAdapter;

    @Override
    protected void initListData() {
        rv = binding.rvProject;
        srf = binding.srf;

        showBarBack(binding.bar.tvTitle, "培训信息", binding.bar.ivBack);

        projectAdapter = new ProjectAdapter();
        projectAdapter.setOnItemChildClickListener((adapter, view, position) -> {
            if (view.getId() == R.id.tv_show) {
                ClassActivity.start(projectAdapter.getItem(position).id + "");
            }
        });

    }


    @Override
    public BaseQuickAdapter getAdapter() {
        return projectAdapter;
    }

    @Override
    protected void getData(long page, long size) {
        Role role = UserManager.getUser().getRole();
        switch (role) {
            case ORGANIZER:
                App.api.getProject1("0", page, size)
                        .enqueue(new JCallback<ProjectList>() {
                            @Override
                            public void onS(Response<ProjectList> response, ProjectList projectList) {
                                getDataSuccess(projectList.data.rows, projectList.data.total);
                            }

                            @Override
                            public void onFailure(Call<ProjectList> call, Throwable t) {
                                super.onFailure(call, t);
                                getDataFail();
                            }
                        });
                break;
            case UNDERTAKER:
                App.api.getProject1("1", page, size)
                        .enqueue(new JCallback<ProjectList>() {
                            @Override
                            public void onS(Response<ProjectList> response, ProjectList projectList) {
                                getDataSuccess(projectList.data.rows, projectList.data.total);
                            }

                            @Override
                            public void onFailure(Call<ProjectList> call, Throwable t) {
                                super.onFailure(call, t);
                                getDataFail();
                            }
                        });
                break;
            case EDUCATION:
                App.api.getProject2(page, size)
                        .enqueue(new JCallback<ProjectList>() {
                            @Override
                            public void onS(Response<ProjectList> response, ProjectList projectList) {
                                getDataSuccess(projectList.data.rows, projectList.data.total);
                            }

                            @Override
                            public void onFailure(Call<ProjectList> call, Throwable t) {
                                super.onFailure(call, t);
                                getDataFail();
                            }
                        });
                break;
            case TRAIN:
                App.api.getProject3(page, size)
                        .enqueue(new JCallback<ProjectList>() {
                            @Override
                            public void onS(Response<ProjectList> response, ProjectList projectList) {
                                getDataSuccess(projectList.data.rows, projectList.data.total);
                            }

                            @Override
                            public void onFailure(Call<ProjectList> call, Throwable t) {
                                super.onFailure(call, t);
                                getDataFail();
                            }
                        });
                break;
        }
    }

}
