package org.dromara.ygpassport.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.json.JSONObject;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.web.core.BaseController;
import org.dromara.ygpassport.domain.vo.*;
import org.dromara.ygpassport.service.ICareerPlansService;
import org.dromara.ygpassport.service.ICareerSkillService;
import org.dromara.ygpassport.service.ICombatProjectService;
import org.dromara.ygpassport.service.IStudentService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 简历模块
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ygpassport/resume")
public class ResumeController extends BaseController {

    private final IStudentService studentService;

    private final ICareerSkillService careerSkillService;

    private final ICareerPlansService careerPlansService;

    private final ICombatProjectService combatProjectService;

    /**
     * 获取学生详情详细信息
     */
    @SaIgnore
    @GetMapping("/{stuNo}")
    public R<ResumeVo> getInfo(@NotNull(message = "主键不能为空")
                               @PathVariable String stuNo) {
        StudentVo studentVo = studentService.queryByStuNo(stuNo);
        List<CareerSkillVo> careerSkillVoList = careerSkillService.queryListByStuNo(stuNo);
        List<CareerPlansVo> careerPlansVoList = careerPlansService.queryListByStuNo(stuNo);
        List<CombatProjectVo> combatProjectVoList = combatProjectService.queryListByStuNo(stuNo);

        ResumeVo resumeVo = new ResumeVo();
        resumeVo.setStudentVo(studentVo);
        resumeVo.setCareerSkillVoList(careerSkillVoList);
        resumeVo.setCareerPlansVoList(careerPlansVoList);
        resumeVo.setCombatProjectVoList(combatProjectVoList);

        return R.ok(resumeVo);
    }

    /**
     * 修改学生照片
     */
    @SaIgnore
    @PutMapping("/editAvatar")
    public R<Void> editAvatar(@RequestBody JSONObject jsonObject){
        String avatar = jsonObject.getStr("avatar");
        String stuNo = jsonObject.getStr("stuNo");
        return toAjax(studentService.updateAvatarByStuNo(avatar, stuNo));
    }

}
