package cn.iocoder.byzs.module.web.controller.admin.course;

import cn.iocoder.byzs.framework.common.pojo.CommonResult;
import cn.iocoder.byzs.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.byzs.module.bjdx.controller.admin.course.vo.CoursePageReqVO;
import cn.iocoder.byzs.module.bjdx.controller.admin.coursetype.vo.CourseTypeListReqVO;
import cn.iocoder.byzs.module.bjdx.controller.admin.coursetype.vo.CourseTypeRespVO;
import cn.iocoder.byzs.module.bjdx.dal.dataobject.coursetype.CourseTypeDO;
import cn.iocoder.byzs.module.bjdx.service.coursetype.CourseTypeService;
import cn.iocoder.byzs.module.web.controller.admin.course.vo.WebCourseVO;
import cn.iocoder.byzs.module.web.service.course.WebCourseServiceImpl;
import jakarta.annotation.security.PermitAll;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import java.util.*;

import cn.iocoder.byzs.framework.common.util.object.BeanUtils;

import cn.iocoder.byzs.module.bjdx.service.course.CourseService;

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

@Tag(name = "Web-前端接口")
@RestController
@RequestMapping("/bjdxWeb/course")
@Validated
public class WebCourseController {

    @Resource
    private CourseService courseService;
    @Resource
    private WebCourseServiceImpl webCourseService;
    @Resource
    private CourseTypeService courseTypeService;


    @GetMapping("/getCourseByTypeId")
    @Operation(summary = "根据类型获得课程列表")
    @Parameter(name = "typeId", description = "编号", required = true, example = "1024")
    public CommonResult<List<WebCourseVO>> getCourseByTypeId(@RequestParam("typeId") Long typeId) {
//        List<CoursePageReqVO> courseList = courseService.getCourseList(new CoursePageReqVO().setCourseType(typeId));

        List<WebCourseVO> courseVoList = webCourseService.getCourseVoByTypeId(typeId);
        return success(courseVoList);
    }

    @GetMapping("/getTypeGrade")
    @Operation(summary = "获得课程-年级")
    public CommonResult<List<CourseTypeRespVO>> getTypeGrade() {
        CourseTypeListReqVO listReqVO = new CourseTypeListReqVO().setCtTypeNode("0");
        List<CourseTypeDO> list = courseTypeService.getCourseTypeList(listReqVO);
        List<CourseTypeRespVO> listVo = BeanUtils.toBean(list, CourseTypeRespVO.class);
        return success(listVo);
    }

    @GetMapping("/getTypeByGradeId")
    @Operation(summary = "获得课程-年级大纲")
    public CommonResult<List<CourseTypeRespVO>> getTypeByGradeId(@RequestParam("id") Integer id) {
        CourseTypeListReqVO listReqVO = new CourseTypeListReqVO().setCtParentId(id).setCtTypeNode("1");
        List<CourseTypeDO> list = courseTypeService.getCourseTypeList(listReqVO);
        List<CourseTypeRespVO> listVo = BeanUtils.toBean(list, CourseTypeRespVO.class);
        return success(listVo);
    }
}