package com.qmth.exam.reserve.controller.admin;

import com.qmth.boot.api.annotation.Aac;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.exam.reserve.bean.login.LoginUser;
import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteReq;
import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteVo;
import com.qmth.exam.reserve.controller.BaseController;
import com.qmth.exam.reserve.service.TimePeriodExamRoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api(tags = "【管理端】考场预约设置相关接口")
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/admin/time/period/exam/room")
@Aac(strict = false, auth = true)
public class TimePeriodExamRoomController extends BaseController {

    @Autowired
    private TimePeriodExamRoomService timePeriodExamRoomService;


    @ApiOperation(value = "日期时段列表")
    @PostMapping(value = "/detail/list")
    public List<TimePeriodExamSiteVo> ListDetail(@ApiParam("考场ID") @RequestParam(required = true) Long examRoomId) {
        if(examRoomId == null) {
            return new ArrayList<>();
        }
        LoginUser loginUser = curLoginUser();
        return timePeriodExamRoomService.ListDetail(loginUser, examRoomId);
    }

    @ApiOperation(value = "考场预约时段编辑")
    @PostMapping(value = "/save")
    public void save(@ApiParam("考点ID") @RequestParam(required = true) Long examRoomId, @RequestBody List<TimePeriodExamSiteReq> timePeriodExamRoomList) {
        LoginUser loginUser = this.curLoginUser();
        timePeriodExamRoomService.save(loginUser.getId(), examRoomId, timePeriodExamRoomList);
    }

}
