package com.live.xmutils;

import com.alibaba.fastjson.JSONObject;
import com.live.client.XMAppApi;
import com.live.enums.ApiModele;
import com.live.enums.RequestType;
import com.live.enums.Terminal;
import com.live.utils.RandomStringUtil;
import com.live.utils.XMBaseTest;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class GetLiveCourseData extends XMBaseTest {

    public JSONObject getLargeClassLiveList() {

        dataApi.setApiModule(ApiModele.CloudClass_B) // API 所属模块  必传 读取配置文件config.properties配置的api地址
                .setApiName("API_getLargeClassLiveList") // API 名称  必传
                .setLoginUser("zhangy-b")         // http 接口，测试账号 必传
                .setTerminal(Terminal.B);             // 所属端位（B端，C端，M端等, 必传）

        super.beforeDataRequest();


        Map bodyMap = new HashMap();
        bodyMap.put("current", 1);
        bodyMap.put("instId", dataApi.getLoginInfo().getInstId());
        bodyMap.put("size", 10);
        String bodydata = JSONObject.toJSONString(bodyMap);

        dataApi.doRequest(RequestType.JSON, params, bodydata, dataheadrs);

        JSONObject liveCourseList=dataApi.getBodyInJSON();

        return liveCourseList;
    }

    public JSONObject getLargeClassLiveListFinish() {

        dataApi.setApiModule(ApiModele.CloudClass_B) // API 所属模块  必传 读取配置文件config.properties配置的api地址
                .setApiName("API_getLargeClassLiveList") // API 名称  必传
                .setLoginUser("zhangy-b")         // http 接口，测试账号 必传
                .setTerminal(Terminal.B);             // 所属端位（B端，C端，M端等, 必传）

        super.beforeDataRequest();

        Map bodyMap = new HashMap();
        bodyMap.put("current", 1);
        bodyMap.put("instId", "1235115978015883266");
        bodyMap.put("size", 10);
        bodyMap.put("courseState", "FINISH");
        String bodydata = JSONObject.toJSONString(bodyMap);

        dataApi.doRequest(RequestType.JSON, params, bodydata, dataheadrs);

        JSONObject liveCourseList=dataApi.getBodyInJSON();

        return liveCourseList;
    }

    public JSONObject getLargeClassLiveListExpired() {

        dataApi.setApiModule(ApiModele.CloudClass_B) // API 所属模块  必传 读取配置文件config.properties配置的api地址
                .setApiName("API_getLargeClassLiveList") // API 名称  必传
                .setLoginUser("zhangy-b")         // http 接口，测试账号 必传
                .setTerminal(Terminal.B);             // 所属端位（B端，C端，M端等, 必传）

        super.beforeDataRequest();

        Map bodyMap = new HashMap();
        bodyMap.put("current", 1);
        bodyMap.put("instId", "1235115978015883266");
        bodyMap.put("size", 10);
        bodyMap.put("courseState", "EXPIRED");
        String bodydata = JSONObject.toJSONString(bodyMap);

        dataApi.doRequest(RequestType.JSON, params, bodydata, dataheadrs);

        JSONObject liveCourseList=dataApi.getBodyInJSON();

        return liveCourseList;
    }

    public JSONObject getLargeClassLiveListStarting() {

        dataApi.setApiModule(ApiModele.CloudClass_B) // API 所属模块  必传 读取配置文件config.properties配置的api地址
                .setApiName("API_getLargeClassLiveList") // API 名称  必传
                .setLoginUser("zhangy-b")         // http 接口，测试账号 必传
                .setTerminal(Terminal.B);             // 所属端位（B端，C端，M端等, 必传）

        super.beforeDataRequest();

        Map bodyMap = new HashMap();
        bodyMap.put("current", 1);
        bodyMap.put("instId", xmAppApi.getLoginInfo().getInstId());
        bodyMap.put("size", 10);
        bodyMap.put("courseState", "STARTING");
        String bodydata = JSONObject.toJSONString(bodyMap);

        dataApi.doRequest(RequestType.JSON, params, bodydata, dataheadrs);

        JSONObject liveCourseList=dataApi.getBodyInJSON();

        return liveCourseList;
    }

    public JSONObject changeCourseStateToStarting(String liveCourseId) {

        dataApi.setApiModule(ApiModele.CloudClass_apollo) // API 所属模块  必传 读取配置文件config.properties配置的api地址
                .setApiName("api_changeCourseState") // API 名称  必传
                .setLoginUser("zhangy-b")         // http 接口，测试账号 必传
                .setTerminal(Terminal.B);             // 所属端位（B端，C端，M端等, 必传）

        super.beforeDataRequest();

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("liveCourseId",liveCourseId);
        jsonObject.put("courseState","STARTING");

        dataApi.doRequest(RequestType.JSON, params, jsonObject.toJSONString(), dataheadrs);
        System.out.println(dataApi);
        JSONObject liveCourseList=dataApi.getBodyInJSON();

        return liveCourseList;
    }

    public JSONObject changeCourseStateToFinish(String liveCourseId) {

        dataApi.setApiModule(ApiModele.CloudClass_apollo) // API 所属模块  必传 读取配置文件config.properties配置的api地址
                .setApiName("api_changeCourseState") // API 名称  必传
                .setLoginUser("zhangy-b")         // http 接口，测试账号 必传
                .setTerminal(Terminal.B);             // 所属端位（B端，C端，M端等, 必传）

        super.beforeDataRequest();

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("liveCourseId",liveCourseId);
        jsonObject.put("courseState","FINISH");

        dataApi.doRequest(RequestType.JSON, params, jsonObject.toJSONString(), dataheadrs);
        System.out.println(dataApi);
        JSONObject liveCourseList=dataApi.getBodyInJSON();

        return liveCourseList;
    }

    public JSONObject createLargeClassLive() throws InterruptedException {
        dataApi.setApiModule(ApiModele.CloudClass_B)
                .setApiName("API_createLargeClassLive")
                .setLoginUser("zhangy-b")
                .setTerminal(com.live.enums.Terminal.B);
        super.beforeDataRequest();


        dataApi.doRequest(RequestType.JSON, params, buildCreateLargeClassLiveParam().toJSONString(), dataheadrs);
        TimeUnit.SECONDS.sleep(3);

        JSONObject liveCourse=dataApi.getBodyInJSON();
        return liveCourse;
    }

    //组装大班直播新增的数据
    public JSONObject buildCreateLargeClassLiveParam() {
        JSONObject largeClassLive = new JSONObject();
        largeClassLive.put("courseName", RandomStringUtil.randomNumber(14, "live_course_"));
        largeClassLive.put("teacherId","1235115979473997826");
        largeClassLive.put("startTime",System.currentTimeMillis() + 60 * 1000);
        largeClassLive.put("endTime",System.currentTimeMillis() + 30 * 60 * 1000);
        largeClassLive.put("needRecord","NO");
        largeClassLive.put("liveType","LARGE_CLASS_LIVE");
        largeClassLive.put("consumeHourNum",1);
        largeClassLive.put("consumeClassTime","1");

        return largeClassLive;
    }

    public JSONObject getInteractionClassLiveList() {

        dataApi.setApiModule(ApiModele.CloudClass_B) // API 所属模块  必传 读取配置文件config.properties配置的api地址
                .setApiName("API_getInteractionClassLiveList") // API 名称  必传
                .setLoginUser("zhangy-b")         // http 接口，测试账号 必传
                .setTerminal(Terminal.B);             // 所属端位（B端，C端，M端等, 必传）

        super.beforeDataRequest();


        Map bodyMap = new HashMap();
        bodyMap.put("current", 1);
        bodyMap.put("instId", dataApi.getLoginInfo().getInstId());
        bodyMap.put("size", 10);
        String bodydata = JSONObject.toJSONString(bodyMap);

        dataApi.doRequest(RequestType.JSON, params, bodydata, dataheadrs);

        JSONObject liveCourseList=dataApi.getBodyInJSON();

        return liveCourseList;
    }

    public JSONObject getInteractionClassLiveList1(String courseName) {

        dataApi.setApiModule(ApiModele.CloudClass_B) // API 所属模块  必传 读取配置文件config.properties配置的api地址
                .setApiName("API_getInteractionClassLiveList") // API 名称  必传
                .setLoginUser("zhangy-b")         // http 接口，测试账号 必传
                .setTerminal(Terminal.B);             // 所属端位（B端，C端，M端等, 必传）

        super.beforeDataRequest();

        Map bodyMap = new HashMap();
        bodyMap.put("current", 1);
        bodyMap.put("instId", dataApi.getLoginInfo().getInstId());
        bodyMap.put("size", 10);
        bodyMap.put("courseName", courseName);
        String bodydata = JSONObject.toJSONString(bodyMap);

        dataApi.doRequest(RequestType.JSON, params, bodydata, dataheadrs);

        JSONObject liveCourseList=dataApi.getBodyInJSON();

        return liveCourseList;
    }

    public JSONObject getInteractionClassLiveListWithStatus(String courseState) {

        dataApi.setApiModule(ApiModele.CloudClass_B) // API 所属模块  必传 读取配置文件config.properties配置的api地址
                .setApiName("API_getInteractionClassLiveList") // API 名称  必传
                .setLoginUser("zhangy-b")         // http 接口，测试账号 必传
                .setTerminal(Terminal.B);             // 所属端位（B端，C端，M端等, 必传）

        super.beforeDataRequest();

        Map bodyMap = new HashMap();
        bodyMap.put("current", 1);
        bodyMap.put("instId", dataApi.getLoginInfo().getInstId());
        bodyMap.put("size", 10);
        bodyMap.put("courseState", courseState);
        String bodydata = JSONObject.toJSONString(bodyMap);

        dataApi.doRequest(RequestType.JSON, params, bodydata, dataheadrs);

        JSONObject liveCourseList=dataApi.getBodyInJSON();

        return liveCourseList;
    }


    public JSONObject createLargeInteractionClassLive() throws InterruptedException {
        dataApi.setApiModule(ApiModele.CloudClass_B)
                .setApiName("API_createCourse")
                .setLoginUser("zhangy-b")
                .setTerminal(com.live.enums.Terminal.B);
        super.beforeDataRequest();


        dataApi.doRequest(RequestType.JSON, params, buildCreateLargeInteractionClassLiveParam().toJSONString(), dataheadrs);
        TimeUnit.SECONDS.sleep(3);

        JSONObject liveCourse=dataApi.getBodyInJSON();
        return liveCourse;
    }

    //组装大班互动课新增的数据
    public JSONObject buildCreateLargeInteractionClassLiveParam() {
        JSONObject largeInteractionClassLive = new JSONObject();
        largeInteractionClassLive.put("courseName", RandomStringUtil.randomNumber(14, "course_"));
        largeInteractionClassLive.put("teacherId","1235115979473997826");
        largeInteractionClassLive.put("startTime",System.currentTimeMillis() + 60 * 1000);
        largeInteractionClassLive.put("endTime",System.currentTimeMillis() + 30 * 60 * 1000);
        largeInteractionClassLive.put("needRecord","NO");
        largeInteractionClassLive.put("liveType","LARGE_CLASS_INTERACTION");
        largeInteractionClassLive.put("consumeHourNum",1);
        largeInteractionClassLive.put("consumeClassTime","1");
        largeInteractionClassLive.put("podium","12");

        return largeInteractionClassLive;
    }

}
