package com.hxhq.business.controller;

import java.util.List;

import cn.hutool.extra.pinyin.PinyinUtil;
import com.hxhq.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hxhq.business.domain.Template;
import com.hxhq.business.service.ITemplateService;
import com.hxhq.common.core.web.controller.BaseController;
import com.hxhq.common.core.web.domain.AjaxResult;
import com.hxhq.common.core.web.page.TableDataInfo;


/**
 * 模板Controller
 *
 * @author hxhq
 * @date 2025-12-23
 */
@RestController
@RequestMapping("/business/template")
public class TemplateController extends BaseController
{
    @Autowired
    private ITemplateService templateService;

    /**
     * 查询模板列表
     */
    @RequiresPermissions("business:template:list")
    @GetMapping("/list")
    public TableDataInfo list(Template template)
    {
        startPage();
        List<Template> list = templateService.queryList(template);
        return getDataTable(list);
    }

    /**
     * 获取模板详细信息
     */
    @RequiresPermissions("business:template:list")
    @GetMapping(value = "/info")
    public AjaxResult getInfo(Long id)
    {
        return AjaxResult.success(templateService.getById(id));
    }

    /**
     * 新增测试信息 todo:后期删除
     */
    @PostMapping("/save")
    public AjaxResult save(@RequestBody Template template)
    {
        template.setShowSn("MB"+PinyinUtil.getFirstLetter(template.getName(),"").toUpperCase()+"V1.0");
        templateService.saveOrUpdate(template);
        return AjaxResult.success();
    }

    /**
     * 删除测试信息 todo:后期删除
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Template template)
    {
        return toAjax(templateService.removeById(template.getId()));
    }
}
