package com.koobietech.eas.controller;

import com.github.pagehelper.PageHelper;
import com.koobietech.eas.common.result.JsonResult;
import com.koobietech.eas.common.result.PageData;
import com.koobietech.eas.dao.dto.ConflictDto;
import com.koobietech.eas.mbg.model.EasEduSchedule;
import com.koobietech.eas.mbg.model.EasSysUserinfo;
import com.koobietech.eas.service.EasEduScheduleService;
import com.koobietech.eas.service.EasSysUserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Tag(name = "课程表模块")
@RequestMapping("/schedule")
public class EasEduScheduleController {


    @Resource
    EasEduScheduleService easEduScheduleService;

    @PostMapping("/add")
    @Operation(summary = "添加课程表", description = "根据课程和重复预约次数(接下来连续多少天都预约这节课)录入基本课程信息")
    public JsonResult add(@RequestBody EasEduSchedule schedule, @RequestParam int repeatTime) {
        Boolean ret = easEduScheduleService.add(schedule, repeatTime);
        if (ret) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除课程表", description = "删除课程表数据根据ID")
    public JsonResult delete(@RequestParam Long id) {
        Boolean ret = easEduScheduleService.delete(id);
        if (ret) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }

    @PutMapping("/update")
    @Operation(summary = "更新课程表", description = "更新课程信息")
    public JsonResult update(@RequestBody EasEduSchedule schedule) {
        Boolean ret = easEduScheduleService.update(schedule);
        if (ret) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }

    @PostMapping("/query")
    @Operation(summary = "查询课程表", description = "根据参数查询课程表信息")
    public JsonResult query(@RequestBody(required = false) EasEduSchedule schedule,
                            @RequestParam Long pageNum, @RequestParam Long pageSize) {


        PageHelper.startPage(Math.toIntExact(pageNum), Math.toIntExact(pageSize));
        PageData ret = easEduScheduleService.query(schedule);
        System.out.println(ret.toString());
        return JsonResult.data(ret);
    }

    @PutMapping("/queryConflict")
    @Operation(summary = "查询排课是否冲突", description = "根据参数查询排课是否冲突")
    public JsonResult queryConflict(@RequestBody ConflictDto conflictDto) {
        Boolean ret = easEduScheduleService.queryConflict(conflictDto);
        if (ret) {
            return JsonResult.data("排课没有冲突");
        }
        return JsonResult.data("排课有冲突");
    }


}
