package cn.iocoder.yudao.module.base.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.base.service.DlDriveSchoolCourseService;
import cn.iocoder.yudao.module.base.vo.DlDriveSchoolCourseVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 课程管理")
@RestController
@RequestMapping("/base/dl-drive-school-course")
@Validated
public class DlDriveSchoolCourseController {

    @Resource
    private DlDriveSchoolCourseService courseService;


    /**
     * 分页获取课程信息
     *
     * @param pageReqVO {@link DlDriveSchoolCourseVO}
     * @param pageNo    分页参数-第几页
     * @param pageSize  分页参数-当前页有多少条数据
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<com.baomidou.mybatisplus.core.metadata.IPage < ?>>
     * @author PQZ
     * @date 22:20 2025/1/16
     **/
    @GetMapping("/page")
    @Operation(summary = "分页获取课程信息")
    public CommonResult<IPage<?>> getDlDriveSchoolCoursePage(DlDriveSchoolCourseVO pageReqVO,
                                                             @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<DlDriveSchoolCourseVO> page = new Page<>(pageNo, pageSize);
        return success(courseService.queryListPage(pageReqVO, page));
    }

    /**
     * 不分页获取课程信息
     *
     * @param pageReqVO {@link DlDriveSchoolCourseVO}
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.util.List < ?>>
     * @author PQZ
     * @date 22:22 2025/1/16
     **/
    @GetMapping("/list")
    @Operation(summary = "不分页获取课程信息")
    public CommonResult<List<?>> getDlDriveSchoolCourseList(DlDriveSchoolCourseVO pageReqVO) {
        return success(courseService.queryList(pageReqVO));
    }

    /**
     * 保存课程信息
     *
     * @param saveVO {@link DlDriveSchoolCourseVO}
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 22:24 2025/1/16
     **/
    @PostMapping("/save")
    @Operation(summary = "保存课程信息")
    public CommonResult<Boolean> saveSchoolCoach(@Valid @RequestBody DlDriveSchoolCourseVO saveVO) {
        courseService.saveDriveSchoolCourse(saveVO);
        return success(true);
    }


    /**
     * 删除课程信息
     *
     * @param id 课程id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 22:25 2025/1/16
     **/
    @DeleteMapping("/delete")
    @Operation(summary = "删除课程信息")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteCourse(@RequestParam("id") String id) {
        courseService.deleteCourse(id);
        return success(true);
    }


    /**
     * 获取课程信息
     *
     * @param id 课程id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.module.base.vo.DlDriveSchoolCoachRespVO>
     * @author PQZ
     * @date 22:26 2025/1/16
     **/
    @GetMapping("/get")
    @Operation(summary = "获取课程信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<DlDriveSchoolCourseVO> getDlDriveSchoolCoach(@RequestParam("id") String id) {
        return success(courseService.queryDetailById(id));
    }


}
