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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.base.entity.DlDriveSchoolStudent;
import cn.iocoder.yudao.module.base.service.DlDriveSchoolStudentService;
import cn.iocoder.yudao.module.base.vo.DlDriveSchoolStudentVO;
import cn.iocoder.yudao.module.jx.core.controller.BaseController;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.beans.factory.annotation.Autowired;
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 java.util.Set;

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

@Tag(name = "驾校学员")
@RestController
@RequestMapping("/small/dl-drive-school-student")
@Validated
public class DlDriveSchoolStudentSmallProgramController extends BaseController {

    @Resource
    private DlDriveSchoolStudentService schoolStudentService;

    @Autowired
    private DlDriveSchoolStudentService studentService;

    @Resource
    private AdminUserService userService;

    @PostMapping("/create")
    @Operation(summary = "创建驾校学员")
    @TenantIgnore
    public CommonResult<String> createDlDriveSchoolStudent(@Valid @RequestBody DlDriveSchoolStudentVO createReqVO) {
        return success(schoolStudentService.createDlDriveSchoolStudent(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新驾校学员")
    public CommonResult<Boolean> updateDlDriveSchoolStudent(@Valid @RequestBody DlDriveSchoolStudentVO updateReqVO) {
        schoolStudentService.updateDlDriveSchoolStudent(updateReqVO);
        return success(true);
    }

    /**
     * 获取学员详细信息
     *
     * @param id 学员id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.module.base.vo.DlDriveSchoolStudentVO>
     * @author PQZ
     * @date 9:58 2025/2/10
     **/
    @GetMapping("/get")
    @Operation(summary = "获得驾校学员")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<DlDriveSchoolStudentVO> getDlDriveSchoolStudent(@RequestParam("id") String id) {
        return success(schoolStudentService.queryStudentById(id));
    }

    /**
     * 根据userID查学员详情
     *
     * @param userId 用户ID
     * @return cn.iocoder.yudao.module.base.entity.DlDriveSchoolStudent
     * @author vinjor-M
     * @date 22:17 2025/1/20
     **/
    @GetMapping("/getByUserId")
    @TenantIgnore
    public CommonResult<DlDriveSchoolStudent> getStudentByUserId(Long userId) {
        return success(studentService.getStudentByUserId(userId));
    }

    @GetMapping("/getUsersInfo")
    @TenantIgnore
    public CommonResult<AdminUserDO> getUsersInfo(){
        LoginUser user = SecurityFrameworkUtils.getLoginUser();
        if (user == null) {
            return success("未登录");
        }
        Long userId = user.getId();
        AdminUserDO sysUser = userService.getUser(userId);
        return success(sysUser);
    }
}
