package org.dromara.system.controller.system;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.SysRecipeCategoryVo;
import org.dromara.system.domain.bo.SysRecipeCategoryBo;
import org.dromara.system.service.ISysRecipeCategoryService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 食谱分类管理
 *
 * @author Lion Li
 * @date 2025-07-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/recipeCategory")
public class SysRecipeCategoryController extends BaseController {

    private final ISysRecipeCategoryService sysRecipeCategoryService;

    /**
     * 查询食谱分类管理列表
     */
    @SaCheckPermission("system:recipeCategory:list")
    @GetMapping("/list")
    public TableDataInfo<SysRecipeCategoryVo> list(SysRecipeCategoryBo bo, PageQuery pageQuery) {
        return sysRecipeCategoryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出食谱分类管理列表
     */
    @SaCheckPermission("system:recipeCategory:export")
    @Log(title = "食谱分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysRecipeCategoryBo bo, HttpServletResponse response) {
        List<SysRecipeCategoryVo> list = sysRecipeCategoryService.queryList(bo);
        ExcelUtil.exportExcel(list, "食谱分类管理", SysRecipeCategoryVo.class, response);
    }

    /**
     * 获取食谱分类管理详细信息
     *
     * @param recipeCategoryId 主键
     */
    @SaCheckPermission("system:recipeCategory:query")
    @GetMapping("/{recipeCategoryId}")
    public R<SysRecipeCategoryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long recipeCategoryId) {
        return R.ok(sysRecipeCategoryService.queryById(recipeCategoryId));
    }

    /**
     * 新增食谱分类管理
     */
    @SaCheckPermission("system:recipeCategory:add")
    @Log(title = "食谱分类管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysRecipeCategoryBo bo) {
        return toAjax(sysRecipeCategoryService.insertByBo(bo));
    }

    /**
     * 修改食谱分类管理
     */
    @SaCheckPermission("system:recipeCategory:edit")
    @Log(title = "食谱分类管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysRecipeCategoryBo bo) {
        return toAjax(sysRecipeCategoryService.updateByBo(bo));
    }

    /**
     * 删除食谱分类管理
     *
     * @param recipeCategoryIds 主键串
     */
    @SaCheckPermission("system:recipeCategory:remove")
    @Log(title = "食谱分类管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recipeCategoryIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] recipeCategoryIds) {
        return toAjax(sysRecipeCategoryService.deleteWithValidByIds(List.of(recipeCategoryIds), true));
    }
}
