package com.xhkjedu.slive.controller.agora;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.slive.model.agora.TAgoralicense;
import com.xhkjedu.slive.service.agora.AgoralicenseService;
import com.xhkjedu.slive.vo.agora.AgoralicenseVo;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
import com.xhkjedu.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
* @author ywx
* @classname TAgoraliceseController
* @description
* @date 2021/03/29 17:01
**/
@RestController
@RequestMapping("/license")
public class AgoralicenseController {
    @Resource
    private AgoralicenseService agoralicenseService;

    @PostMapping("/list")
    public ResultVo list(@RequestBody TAgoralicense license) {
        PageHelper.startPage(license.getPage(), license.getPageSize());
        List<AgoralicenseVo> list = agoralicenseService.listAll(license);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
        return new ResultVo(0,"获取license列表成功",pageResult);
    }

    //学生退出直播
    @PostMapping("/out_live")
    public ResultVo outLive(@RequestBody TAgoralicense license) {
        Integer userid = license.getUserid();
        String cloudcode = license.getCloudcode();
        N_Utils.validation(new Object[]{userid, "用户id", 1,cloudcode,"云平台码",2});
        return agoralicenseService.outLive(userid, cloudcode);
    }
}
