package org.xyzh.study.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xyzh.api.study.course.CourseService;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.core.page.PageRequest;
import org.xyzh.common.dto.study.TbCourse;
import org.xyzh.common.dto.study.TbCourseChapter;
import org.xyzh.common.vo.ChapterVO;
import org.xyzh.common.vo.CourseVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;


/**
 * @description 课程控制器
 * @filename CourseController.java
 * @author yslg
 * @copyright xyzh
 * @since 2025-10-15
 */
@RestController
@RequestMapping("/study/courses")
public class CourseController {
    private static final Logger logger = LoggerFactory.getLogger(CourseController.class);

    @Autowired
    private CourseService courseService;

    /**
     * 获取课程列表
     */
    @GetMapping("/list")
    public ResultDomain<TbCourse> getCourseList(TbCourse filter) {
        return courseService.getCourseList(filter);
    }

    /**
     * 分页获取课程列表
     */
    @PostMapping("/page")
    public ResultDomain<TbCourse> getCoursePage(@RequestBody PageRequest<TbCourse> pageRequest) {
        return courseService.getCoursePage(pageRequest);
    }

    /**
     * 根据ID获取课程详情
     */
    @GetMapping("/{courseID}")
    public ResultDomain<CourseVO> getCourseById(@PathVariable("courseID") String courseID) {
        return courseService.getCourseById(courseID);
    }

    /**
     * 创建课程
     */
    @PostMapping("/course")
    public ResultDomain<CourseVO> createCourse(@RequestBody CourseVO courseVO) {
        return courseService.createCourse(courseVO);
    }

    /**
     * 更新课程
     */
    @PutMapping("/course")
    public ResultDomain<TbCourse> updateCourse(@RequestBody TbCourse course) {
        return courseService.updateCourse(course);
    }

    /**
     * 删除课程
     */
    @DeleteMapping("/course")
    public ResultDomain<Boolean> deleteCourse(@PathVariable String courseID) {
        return courseService.deleteCourse(courseID);
    }

    /**
     * 更新课程状态
     */
    @PutMapping("/{courseID}/status")
    public ResultDomain<TbCourse> updateCourseStatus(
            @PathVariable String courseID,
            @RequestParam Integer status) {
        return courseService.updateCourseStatus(courseID, status);
    }

    /**
     * 增加课程浏览次数
     */
    @PostMapping("/{courseID}/view")
    public ResultDomain<TbCourse> incrementViewCount(@PathVariable String courseID) {
        return courseService.incrementViewCount(courseID);
    }

    /**
     * 增加课程学习人数
     */
    @PostMapping("/{courseID}/learn")
    public ResultDomain<TbCourse> incrementLearnCount(@PathVariable String courseID) {
        return courseService.incrementLearnCount(courseID);
    }

}
