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.TimePeriodExamSiteService;
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;
import java.util.Objects;

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

    @Autowired
    private TimePeriodExamSiteService timePeriodExamSiteService;

    @ApiOperation(value = "时段区间列表")
    @PostMapping(value = "/list")
    public List<String> list(@ApiParam("预约任务ID") @RequestParam(required = false) Long taskId) {
        return timePeriodExamSiteService.listTimePeriod(taskId);
    }

    @ApiOperation(value = "日期时段列表")
    @PostMapping(value = "/detail/list")
    public List<TimePeriodExamSiteVo> ListDetail(@ApiParam("考点ID") @RequestParam(required = false) Long examSiteId) {
        if(examSiteId == null) {
            return new ArrayList<>();
        }
        return timePeriodExamSiteService.ListDetail(examSiteId);
    }

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