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.CmsCate;
import com.goldenwater.slgc.service.CmsCateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "12. 内容分类管理")
@RestController
@RequestMapping("/slgc/cms-cate")
public class CmsCateController extends BaseController {
    @Autowired
    private CmsCateService cmsCateService;

    @Operation(summary = "12.01 查询内容分类列表")
    @GetMapping("/list")
    public TableDataInfo list(CmsCate cmsCate) {
        startPage();
        List<CmsCate> list = cmsCateService.selectCmsCateList(cmsCate);
        return getDataTable(list);
    }

    @Operation(summary = "12.02 获取内容分类详细信息")
    @GetMapping(value = "/{cateId}")
    public AjaxResult getInfo(@PathVariable String cateId) {
        return success(cmsCateService.selectCmsCateById(cateId));
    }

    @Operation(summary = "12.03 新增内容分类")
    @Log(title = "内容分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsCate cmsCate) {
        return toAjax(cmsCateService.insertCmsCate(cmsCate));
    }

    @Operation(summary = "12.04 修改内容分类")
    @Log(title = "内容分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsCate cmsCate) {
        return toAjax(cmsCateService.updateCmsCate(cmsCate));
    }

    @Operation(summary = "12.05 删除内容分类")
    @Log(title = "内容分类管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cateIds}")
    public AjaxResult remove(@PathVariable String[] cateIds) {
        return toAjax(cmsCateService.deleteCmsCateByIds(cateIds));
    }

    @Operation(summary = "12.06 获取内容分类树")
    @GetMapping("/tree")
    public AjaxResult getTree() {
        return success(cmsCateService.getTree());
    }

    @Operation(summary = "12.07 查询子分类列表")
    @GetMapping("/subList/{catePid}")
    public AjaxResult getSubList(@PathVariable String catePid) {
        return success(cmsCateService.findSubList(catePid));
    }
}
