package com.seer.teach.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.admin.request.GenerateQuestionImageReq;
import com.seer.teach.admin.service.AdminQuestionImageService;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.enums.AiScenarioCodeEnum;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import jakarta.validation.Valid;
import java.util.List;

/**
 * <p>
 * 管理端 - 题目图片生成
 * </p>
 *
 * @author Lingma
 * @since 2025-10-28
 */
@RestController
@RequestMapping("/teacher/question-images")
@RequiredArgsConstructor
@Tag(name = "管理端 - 题目图片生成")
@Validated
public class AdminQuestionImageController {

    private final AdminQuestionImageService adminQuestionImageService;

    @PostMapping("/generate-task")
    @Operation(summary = "根据题目内容生成相关图片")
    @SaCheckPermission("teacher:admin:question-images:generate")
    public ResultBean<String> generateQuestionImages(@Parameter(description = "生成图片参数") @Valid @RequestBody GenerateQuestionImageReq req) {
        req.setScenarioCode(AiScenarioCodeEnum.KNOWLEDGE_POINT_GENERATE_IMAGES.getCode());
        req.setUserId(StpUtil.getLoginIdAsInt());
        String taskId = adminQuestionImageService.generateQuestionImages(req);
        return ResultBean.success(taskId);
    }

    @PostMapping("/get-generate-img-prop")
    @Operation(summary = "获取生成图片的提示词")
    @SaCheckPermission("teacher:admin:question-images:generate")
    public ResultBean<String> getGenerateQuestionImageProp(@Parameter(description = "生成图片参数") @Valid @RequestBody GenerateQuestionImageReq req) {
        return ResultBean.success(adminQuestionImageService.getGenerateQuestionImageProp(req));
    }

    @GetMapping("/get-task-result")
    @Operation(summary = "获取任务结果")
    @SaCheckPermission("teacher:admin:question-images:get-task-result")
    public ResultBean<List<String>> getTaskResult(@Parameter(description = "任务Id") @RequestParam String taskId) {
        return ResultBean.success(adminQuestionImageService.getTaskResult(taskId));
    }
}