package com.ruoyi.web.controller.course;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.RestResponse;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.course.domain.req.ReqSearchClaTime;
import com.ruoyi.course.domain.time.ClaTimeCalendarItem;
import com.ruoyi.course.domain.time.RespBusinessClaTimeCalendar;
import com.ruoyi.course.mapper.ScClaTimeMapper;
import com.ruoyi.course.service.ScClaTimeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;


@RestController
@RequestMapping("/api/course")
public class CourseController extends BaseController {


    @Autowired
    private ScClaTimeService scClaTimeService;


    /**
     * 我的课表-学员
     * @return
     */
    @GetMapping("/getCourseList")
    public RestResponse getCourseList(){
        ReqSearchClaTime reqSearchClaTime=new ReqSearchClaTime();
        RespBusinessClaTimeCalendar c =scClaTimeService.searchListForCalendar(reqSearchClaTime);
        return new RestResponse().setSuccess(true).setMessage("成功").setData(c);
    }

    /**
     * 我的课表
     * @return
     */
    @PostMapping("/getCourseListByDate")
    public RestResponse getCourseListByDate(@RequestBody Map map){
       String dateStr= map.get("date").toString();
//       Date date= DateUtil.parse(dateStr,"yyyy-MM-dd");
       return scClaTimeService.getCourseListByDate(dateStr);

    }

    @PostMapping("/getCourseDetail")
    public RestResponse getCourseDetail(@RequestBody Map<String,Long> map){
        Long courseTimeId=map.get("courseTimeId");
        return scClaTimeService.getCourseDetail(courseTimeId);
    }
    /**
     * 预约课程
     * @param searchClaTime
     * @return
     */
    @PostMapping("/bookCourse")
    public RestResponse bookCourse(@RequestBody ReqSearchClaTime searchClaTime){

        return scClaTimeService.bookCourse(searchClaTime);
    }

    /**
     * 我的预约
     * @param
     * @return
     */
    @GetMapping("/bookCourseList")
    public RestResponse bookCourseList(){
        return new RestResponse().setData(scClaTimeService.bookCourseList());
    }

    /**
     * 预约详情
     * @param map
     * @return
     */
    @PostMapping("/bookCourseDetail")
    public RestResponse bookCourseDetail(@RequestBody Map map){
        Long bookId =Long.parseLong(map.get("bookId").toString());
        return scClaTimeService.bookCourseDetail(bookId);
    }

    /**
     * 取消预约
     * @return
     */
    @PostMapping("/cancelCourse")
    public RestResponse cancelCourse(@RequestBody Map map){
        Long courseTimeId =Long.parseLong(map.get("courseTimeId").toString());
        return scClaTimeService.cancelCourse(courseTimeId);
    }




}
