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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.jx.core.controller.BaseController;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.base.entity.DlDriveSchoolCoach;
import cn.iocoder.yudao.module.base.entity.DlDriveSchoolCoachCourse;
import cn.iocoder.yudao.module.base.service.DlDriveSchoolCoachCourseService;
import cn.iocoder.yudao.module.base.service.DlDriveSchoolCoachService;
import cn.iocoder.yudao.module.base.vo.DlDriveSchoolCoachPageReqVO;
import cn.iocoder.yudao.module.base.vo.DlDriveSchoolCoachRespVO;
import cn.iocoder.yudao.module.base.vo.DlDriveSchoolCoachVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;

import java.util.List;

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

@Tag(name = "小程序 - 驾校教练")
@RestController
@RequestMapping("/dl-drive-school-coach-small")
@Validated
public class DlDriveSchoolCoachSmallProgramController extends BaseController{

    @Resource
    private DlDriveSchoolCoachService dlDriveSchoolCoachService;

    @Resource
    private DlDriveSchoolCoachCourseService coachCourseService;

    /**
     * 驾校教练、普通员工列表
     *
     * @param pageReqVO {@link DlDriveSchoolCoachPageReqVO}
     * @param pageNo    分页参数第几页
     * @param pageSize  分页参数每页多少条数据
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<com.baomidou.mybatisplus.core.metadata.IPage < ?>>
     * @author PQZ
     * @date 14:58 2025/1/16
     **/
    @GetMapping("/page")
    @Operation(summary = "获得驾校教练分页")
    @TenantIgnore
    public CommonResult<IPage<?>> getDlDriveSchoolCoachPage(DlDriveSchoolCoachPageReqVO pageReqVO,
                                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<DlDriveSchoolCoachRespVO> page = new Page<>(pageNo, pageSize);
        return success(dlDriveSchoolCoachService.queryListPage(pageReqVO, page));
    }

    /**
     * 不分页获取教练信息
     *
     * @param pageReqVO {@link DlDriveSchoolCoachPageReqVO}
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<com.baomidou.mybatisplus.core.metadata.IPage < ?>>
     * @author PQZ
     * @date 14:25 2025/2/7
     **/
    @GetMapping("/list")
    @Operation(summary = "不分页获取教练信息")
    @TenantIgnore
    public CommonResult<List<?>> listSchoolCoach(DlDriveSchoolCoachPageReqVO pageReqVO) {
        return success(dlDriveSchoolCoachService.listSchoolCoachApp(pageReqVO));
    }

    /**
     * 通过课程id查询课程与教练关联关系
     *
     * @param courseId 课程id
     * @return java.util.List<cn.iocoder.yudao.module.base.entity.DlDriveSchoolCoachCourse>
     * @author PQZ
     * @date 14:17 2025/2/8
     **/
    @GetMapping("/queryCoachByCourseId")
    @TenantIgnore
    public CommonResult<List<DlDriveSchoolCoachCourse>> queryByCourseId(String courseId) {
        return success(coachCourseService.queryByCourseId(courseId));

    }

    /**
     *
     * @author vinjor-M
     * @date 15:41 2025/2/18
     * @param userId userId
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<?>
     **/
    @GetMapping("/getCoachByUserId")
    @Operation(summary = "根据userId获得驾校教练信息")
    @Parameter(name = "userId", description = "用户id", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<?> getCoachByUserId(@RequestParam("userId") Long userId) {
        return success(dlDriveSchoolCoachService.getDlDriveSchoolCoachByUserId(userId));
    }

    /**
     * 通过教练id获取驾校教练
     *
     * @param id 教练id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.module.base.vo.DlDriveSchoolCoachRespVO>
     * @author PQZ
     * @date 21:41 2025/1/16
     **/
    @GetMapping("/get")
    @Operation(summary = "获得驾校教练")
    @TenantIgnore
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<DlDriveSchoolCoachRespVO> getDlDriveSchoolCoach(@RequestParam("id") String id) {
        DlDriveSchoolCoach dlDriveSchoolCoach = dlDriveSchoolCoachService.getDlDriveSchoolCoach(id);
        return success(BeanUtils.toBean(dlDriveSchoolCoach, DlDriveSchoolCoachRespVO.class));
    }

    @GetMapping("/getCoachByUniqueCode")
    @TenantIgnore
    @PermitAll
    public CommonResult<?> getCoachByUniqueCode(@RequestParam("uniqueCode") String uniqueCode) {
        return success(dlDriveSchoolCoachService.getCoachByUniqueCode(uniqueCode));
    }
}
