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

import cn.iocoder.byzs.framework.common.pojo.CommonResult;
import cn.iocoder.byzs.module.web.controller.admin.aiCourseProgress.vo.WebAiCourseProgressDO;
import cn.iocoder.byzs.module.web.service.aiCourseProgress.WebAiCourseProgressServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jodd.util.StringUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

import static cn.iocoder.byzs.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.byzs.framework.common.pojo.CommonResult.success;
import static cn.iocoder.byzs.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.byzs.module.bjdx.enums.ErrorCodeConstants.PROGRESS_NOT_EXISTS;


@Tag(name = "管理后台 - 评估报告-课程开课率")
@RestController
@RequestMapping("/aiCourseReport/progress")
@Validated
public class WebAiCourseProgressController {

    @Resource
    private WebAiCourseProgressServiceImpl progressService;

    @PostMapping("/saveReportProgress")
    @Operation(summary = "保存评估报告进度")
    public CommonResult<Boolean> saveReportProgress(@Valid @RequestBody WebAiCourseProgressDO reportProgressDO) {
        // 校验
        if (StringUtil.isBlank(reportProgressDO.getArpType()) || reportProgressDO.getArpType().equals("courseQuest") && Objects.isNull(reportProgressDO.getArpCourseConfigId())) {
            throw exception(PROGRESS_NOT_EXISTS);
        }
        //用户id
        reportProgressDO.setArpUserId(getLoginUserId());
        // 插入
        progressService.saveReportProgress(reportProgressDO);
        return success(true);
    }
}