package com.ruoyi.generator.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.generator.domain.TemplateFile;
import com.ruoyi.generator.service.ITemplateFileService;

/**
 * 代码模板文件Controller
 *
 * @author ruoyi
 * @date YOUR_CURRENT_DATE
 */
@RestController
@RequestMapping("/generator/templateFile")
public class TemplateFileController extends BaseController
{
    @Autowired
    private ITemplateFileService templateFileService;

    /**
     * 查询代码模板文件列表
     */
    @PreAuthorize("@ss.hasPermi('generator:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(TemplateFile templateFile)
    {
        startPage();
        List<TemplateFile> list = templateFileService.selectTemplateFileList(templateFile);
        return getDataTable(list);
    }

    /**
     * 根据模板ID查询代码模板文件列表
     */
    @PreAuthorize("@ss.hasPermi('generator:template:list')")
    @GetMapping("/listByTemplateId/{templateId}")
    public AjaxResult listByTemplateId(@PathVariable("templateId") Long templateId)
    {
        List<TemplateFile> list = templateFileService.selectTemplateFilesByTemplateId(templateId);
        return success(list);
    }

    /**
     * 获取代码模板文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('generator:template:query')")
    @GetMapping(value = "/{templateFileId}")
    public AjaxResult getInfo(@PathVariable("templateFileId") Long templateFileId)
    {
        return success(templateFileService.selectTemplateFileByTemplateFileId(templateFileId));
    }

    /**
     * 新增代码模板文件
     */
    @PreAuthorize("@ss.hasPermi('generator:template:add')")
    @Log(title = "代码模板文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TemplateFile templateFile)
    {
        return toAjax(templateFileService.insertTemplateFile(templateFile));
    }

    /**
     * 修改代码模板文件
     */
    @PreAuthorize("@ss.hasPermi('generator:template:edit')")
    @Log(title = "代码模板文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TemplateFile templateFile)
    {
        return toAjax(templateFileService.updateTemplateFile(templateFile));
    }

    /**
     * 删除代码模板文件
     */
    @PreAuthorize("@ss.hasPermi('generator:template:remove')")
    @Log(title = "代码模板文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{templateFileIds}")
    public AjaxResult remove(@PathVariable Long[] templateFileIds)
    {
        return toAjax(templateFileService.deleteTemplateFileByTemplateFileIds(templateFileIds));
    }

    /**
     * 根据模板ID删除代码模板文件
     */
    @PreAuthorize("@ss.hasPermi('generator:template:remove')")
    @Log(title = "代码模板文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteByTemplateId/{templateId}")
    public AjaxResult deleteByTemplateId(@PathVariable Long templateId)
    {
        return toAjax(templateFileService.deleteTemplateFilesByTemplateId(templateId));
    }
} 