package com.cooleshow.teacher.presenter.minestyle;

import android.app.Activity;
import android.util.Log;

import com.cooleshow.base.constanst.UploadConstants;
import com.cooleshow.base.data.net.BaseResponse;
import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.RequestBodyUtil;
import com.cooleshow.base.utils.helper.upload.UploadHelper;
import com.cooleshow.teacher.api.APIService;
import com.cooleshow.teacher.bean.HomePageSheetMusicListBean;
import com.cooleshow.teacher.bean.TeacherSelfStyleInfoBean;
import com.cooleshow.teacher.contract.MineStylePageContract;
import com.cooleshow.teacher.ui.minestyle.MineStylePageActivity;
import com.daya.live_teaching.LiveTeachingApp;
import com.daya.live_teaching.model.FileUploadBean;
import com.daya.live_teaching.repository.ClassRepository;

import java.io.File;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 创建日期：2022/5/13 14:17
 *
 * @author Ryan
 * 类说明：
 */
public class MineStylePagePresenter extends BasePresenter<MineStylePageContract.MineStylePageView> implements MineStylePageContract.Presenter {


    @Override
    public void getTeacherSelfStyle() {
        getView().showLoading();
        addSubscribe(create(APIService.class).getTeacherSelfStyle(), new BaseObserver<TeacherSelfStyleInfoBean>(getView()) {
            @Override
            protected void onSuccess(TeacherSelfStyleInfoBean data) {
                if (getView() != null) {
                    getView().getSelfStyleSuccess(data);
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
                getView().hideLoading();
            }
        });
    }

    public void saveTeacherStyle(String jsonStr) {
        getView().showLoading();
        addSubscribe(create(APIService.class).saveTeacherStyle(RequestBodyUtil.convertToRequestBodyJson(jsonStr)), new BaseObserver<TeacherSelfStyleInfoBean>(getView()) {
            @Override
            protected void onSuccess(TeacherSelfStyleInfoBean data) {
                if (getView() != null) {
                    getView().saveTeacherStyleSuccess(data);
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
                getView().hideLoading();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);

            }
        });
    }

    public void upLoadVideo(Activity activity, String filePath) {
        UploadHelper uploadHelper = new UploadHelper(activity, UploadConstants.UPLOAD_TYPE_OTHER);
        uploadHelper.uploadFile(new File(filePath));
        uploadHelper.setUpLoadCallBack(new UploadHelper.UpLoadCallBack() {
            @Override
            public void onSuccess(String url) {
                if (getView() != null) {
                    TeacherSelfStyleInfoBean.StyleVideoBean styleVideoBean = new TeacherSelfStyleInfoBean.StyleVideoBean();
                    styleVideoBean.videoUrl = url;
                    styleVideoBean.type = 0;
                    getView().upLoadVideoSuccess(styleVideoBean);
                }
            }

            @Override
            public void onFailure() {
                if (getView() != null) {
                    getView().upLoadVideoFailure();
                }
            }
        });
    }
}
