package com.goldenwater.slgc.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
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.goldenwater.common.annotation.Log;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.common.enums.BusinessType;
import com.goldenwater.slgc.domain.CmsArticleFile;
import com.goldenwater.slgc.service.CmsArticleFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "14. 内容文件管理")
@RestController
@RequestMapping("/slgc/cms-file")
public class CmsArticleFileController extends BaseController {
    @Autowired
    private CmsArticleFileService cmsArticleFileService;

    @Operation(summary = "14.01 查询内容文件列表")
    @GetMapping("/list")
    public TableDataInfo list(CmsArticleFile cmsArticleFile) {
        startPage();
        List<CmsArticleFile> list = cmsArticleFileService.selectCmsArticleFileList(cmsArticleFile);
        return getDataTable(list);
    }

    @Operation(summary = "14.02 获取内容文件详细信息")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable String fileId) {
        return success(cmsArticleFileService.selectCmsArticleFileById(fileId));
    }

    @Operation(summary = "14.03 新增内容文件")
    @Log(title = "内容文件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsArticleFile cmsArticleFile) {
        return toAjax(cmsArticleFileService.insertCmsArticleFile(cmsArticleFile));
    }

    @Operation(summary = "14.04 修改内容文件")
    @Log(title = "内容文件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsArticleFile cmsArticleFile) {
        return toAjax(cmsArticleFileService.updateCmsArticleFile(cmsArticleFile));
    }

    @Operation(summary = "14.05 删除内容文件")
    @Log(title = "内容文件管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable String[] fileIds) {
        return toAjax(cmsArticleFileService.deleteCmsArticleFileByIds(fileIds));
    }

    @Operation(summary = "14.06 根据文章ID删除文件")
    @Log(title = "内容文件管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/byAid/{aid}")
    public AjaxResult removeByAid(@PathVariable String aid) {
        return toAjax(cmsArticleFileService.deleteByAid(aid));
    }
}
