package com.ym.mec.web.controller;


import com.ym.mec.biz.dal.entity.ImLiveRoomReservation;
import com.ym.mec.biz.dal.vo.ImLiveBroadcastRoomVo;
import com.ym.mec.biz.service.ImLiveRoomReservationService;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.common.page.WrapperUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.ym.mec.common.controller.BaseController;

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

/**
 * 直播预约记录(ImLiveRoomReservation)表控制层
 *
 * @author hgw
 * @since 2022-05-24 14:54:04
 */
@RestController
@RequestMapping("/imLiveRoomReservation")
public class ImLiveRoomReservationController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ImLiveRoomReservationService imLiveRoomReservationService;


    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", dataType = "Integer", value = "用户id"),
            @ApiImplicitParam(name = "roomUid", dataType = "String", value = "房间uid"),
            @ApiImplicitParam(name = "ops", dataType = "Integer", value = "1 预约  2取消预约")
    })
    @PostMapping("/opsReserve")
    public HttpResponseResult<Object> opsReserve(@RequestBody Map<String, Object> param) {
        Integer ops = WrapperUtil.toInt(param, "ops", "请传入操作类型");
        ImLiveRoomReservation entity = new ImLiveRoomReservation();
        entity.setRoomUid(WrapperUtil.toStr(param, "roomUid", "请传入房间uid"));
        entity.setUserId(WrapperUtil.toInt(param, "userId", "用户id不能为空"));
        //1 预约  2取消预约
        if (ops == 1) {
            imLiveRoomReservationService.add(entity);
        } else if (ops == 2) {
            imLiveRoomReservationService.cancel(entity);
        } else {
            return failed("请传入正确的操作类型");
        }
        return succeed();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "liveState", dataType = "Integer", value = "直播状态 0未开始 1开始 2结束"),
            @ApiImplicitParam(name = "page", dataType = "Integer", value = "页数"),
            @ApiImplicitParam(name = "rows", dataType = "Integer", value = "每页数量"),
    })
    @ApiOperation("学生端-分页查询直播间")
    @PostMapping("/queryPageStudent")
    public HttpResponseResult<PageInfo<ImLiveBroadcastRoomVo>> queryPageStudent(@RequestBody Map<String, Object> param) {
        return succeed(imLiveRoomReservationService.queryPageStudent(param));
    }


}

