package com.cool.modules.aiconfig.controller.admin;

import cn.hutool.json.JSONObject;
import com.cool.core.annotation.CoolRestController;
import com.cool.core.base.BaseController;
import com.cool.modules.aiconfig.entity.AiTemplateEntity;
import com.cool.modules.aiconfig.service.AiTemplateService;
import com.cool.core.request.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import static com.cool.modules.aiconfig.entity.table.AiTemplateEntityTableDef.AI_TEMPLATE_ENTITY;

/**
 * AI模板提示词配置管理
 */
@Tag(name = "AI模板配置", description = "AI模板提示词配置管理")
@CoolRestController(api = {"add", "delete", "update", "page", "list", "info"})
public class AdminAiTemplateController extends BaseController<AiTemplateService, AiTemplateEntity> {

    @Override
    protected void init(HttpServletRequest request, JSONObject requestParams) {
        setPageOption(createOp()
                .keyWordLikeFields(AI_TEMPLATE_ENTITY.TEMPLATE_NAME, AI_TEMPLATE_ENTITY.TEMPLATE_KEY, AI_TEMPLATE_ENTITY.SCENE)
                .fieldEq(AI_TEMPLATE_ENTITY.MODEL_ID, AI_TEMPLATE_ENTITY.SCENE)
        );
    }

    @Operation(summary = "根据场景获取模板列表", description = "根据使用场景获取对应的模板列表")
    @GetMapping("/byScene")
    public R getByScene(@RequestParam String scene) {
        return R.ok(this.service.getByScene(scene));
    }

    @Operation(summary = "根据模型ID获取模板列表", description = "根据模型ID获取对应的模板列表")
    @GetMapping("/byModel")
    public R getByModel(@RequestParam Long modelId) {
        return R.ok(this.service.getByModelId(modelId));
    }
}
