package cn.iocoder.yudao.module.appBase.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.jx.core.controller.BaseController;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolCourse;
import cn.iocoder.yudao.module.jx.service.DrivePayService;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolCourseService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 驾校课程分类Controller
 *
 * @author ruoyi
 * @date 2024-03-21
 */
@RestController
@RequestMapping("/drivingSchool/applet/driveSchoolCourse")
public class DriveSchoolCourseAppletController extends BaseController
{
    @Autowired
    private IDriveSchoolCourseService driveSchoolCourseService;
    @Autowired
    private DrivePayService drivePayService;



    /**
     * 查询驾校课程列表(取三个)
     */
    @GetMapping("/limtList")
    public CommonResult limtList(DriveSchoolCourse driveSchoolCourse)
    {
        List<DriveSchoolCourse> list = driveSchoolCourseService.selectDriveSchoolCourseAppletListAll(driveSchoolCourse);
        if (CollectionUtils.isNotEmpty(list)){
            if (list.size()>3){
                list.subList(0,3);
                return CommonResult.success(list);
            }else {
                return CommonResult.success(list);
            }
        }else {
            return CommonResult.success(list);
        }
    }


    /**
     * 查询驾校课程分类列表（全部）
     */
    @GetMapping("/list")
    public CommonResult<IPage<?>> list(DriveSchoolCourse driveSchoolCourse)
    {
        Page<DriveSchoolCourse> page = new Page<>(driveSchoolCourse.getPageNum(), driveSchoolCourse.getPageSize());
        IPage<DriveSchoolCourse> driveSchoolCourseIPage = driveSchoolCourseService.selectDriveSchoolCourseAppList(driveSchoolCourse, page);
        return CommonResult.success(driveSchoolCourseIPage);
        //return getDataTable(list);
    }

    /**
     * 首页 优惠推荐
     */
    @GetMapping("/favorableList")
    public CommonResult favorableList(DriveSchoolCourse driveSchoolCourse)
    {
        List<DriveSchoolCourse> list = driveSchoolCourseService.selectDriveSchoolCourseAppletFavorableListList(driveSchoolCourse);
        if (CollectionUtils.isNotEmpty(list)){
            if (list.size()>6){
                list.subList(0,6);
                return CommonResult.success(list);
            }else {
                return CommonResult.success(list);
            }
        }else {
            return CommonResult.success(list);
        }
    }


    /**
     * 获取驾校课程分类详细信息
     */
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(driveSchoolCourseService.selectDriveSchoolCourseAppletById(id));
    }
    @PostMapping(value = "/idOcr")
    public CommonResult idOcr(@RequestParam("imagePath") String imagePath) throws TencentCloudSDKException {
        return success(drivePayService.infoCardOCR(imagePath));
    }

}
