package com.wmyun.module.infra.controller.admin.word;

import com.wmyun.farmwork.word.deprecated.core.model.exec.TemplateExecDataModel;
import com.wmyun.farmwork.word.deprecated.core.model.gen.TagsGenDataModel;
import com.wmyun.framework.common.pojo.CommonResult;
import com.wmyun.module.infra.service.file.WordTemplateTagService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: TODO
 * @Date: 2025/3/1 10:31
 * @Created: by ZZSLL
 */

@Tag(name = "管理后台 - Word模板")
@RestController
@RequestMapping("/infra/word")
public class WordTemplateController {

    @Autowired
    private WordTemplateTagService wordService;

    @PostMapping("/file/{fileId}")
    public CommonResult<List<TagsGenDataModel>> requestAllTags(@PathVariable("fileId") String fileId) {
        try {
            return CommonResult.success(wordService.queryAllTag(fileId));
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.error(500, e.getMessage());
        }
    }

    @PostMapping("/file/{fileId}/generate")
    public CommonResult<Object> doGenerate(@PathVariable("fileId") String fileId, @RequestBody TemplateExecDataModel data) {
        try {
            return CommonResult.success(wordService.generateNew(fileId, data));
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.error(500, e.getMessage());
        }
    }
}
