package com.ruoyi.course.controller;


import com.ruoyi.course.mapper.TimeSlotMapper;
import com.ruoyi.course.service.impl.TimeTableManager;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 时间槽表 前端控制器
 * </p>
 *
 * @author xu
 * @since 2025-12-17
 */
@RestController
@RequestMapping("/time-slot")
public class TimeSlotController {

    @Autowired
    private TimeTableManager timeTableManager;
    @Autowired
    private TimeSlotMapper timeSlotMapper;

    @Operation(summary = "初始化时间槽", description = "初始化时间槽数据")
    @PostMapping("/init-time-slots")
    public Map<String, Object> initTimeSlots() {
        Map<String, Object> result = new HashMap<>();

        try {
            timeTableManager.initTimeSlots();

            // 统计初始化结果
            Long count = timeSlotMapper.selectCount(null);

            result.put("success", true);
            result.put("message", "时间槽初始化完成");
            result.put("totalSlots", count);
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "时间槽初始化失败: " + e.getMessage());
        }

        return result;
    }

}
