package com.bonus.canteen.core.cook.controller;

import java.util.List;

import com.bonus.canteen.core.common.utils.TreeNodeUtil;
import com.bonus.canteen.core.cook.vo.CookDishesTypeVO;
import com.bonus.common.log.enums.OperaType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.canteen.core.cook.domain.CookDishesType;
import com.bonus.canteen.core.cook.service.ICookDishesTypeService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;

/**
 * 菜品类型信息Controller
 * 
 * @author xsheng
 * @date 2025-05-25
 */
@Api(tags = "菜品类型信息接口")
@RestController
@RequestMapping("/cook_dishes_type")
public class CookDishesTypeController extends BaseController {
    @Autowired
    private ICookDishesTypeService cookDishesTypeService;

    /**
     * 查询菜品类型信息列表
     */
    @ApiOperation(value = "获取所有菜品类别")
    @GetMapping("/list")
    public AjaxResult list(CookDishesType cookDishesType) {
        List<CookDishesTypeVO> list = cookDishesTypeService.selectList(cookDishesType);
        return AjaxResult.success(TreeNodeUtil.assembleTree(list));
    }


    /**
     * 获取菜品类型信息详细信息
     */
    @ApiOperation(value = "获取菜品类型信息详细信息")
    @GetMapping(value = "/{dishesTypeId}")
    public AjaxResult getInfo(@PathVariable("dishesTypeId") Long dishesTypeId) {
        return success(cookDishesTypeService.selectCookDishesTypeByDishesTypeId(dishesTypeId));
    }

    /**
     * 新增菜品类型信息
     */
    @ApiOperation(value = "新增菜品类型信息")
    @SysLog(title = "菜品类型信息", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增菜品类型信息")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CookDishesType cookDishesType) {
        try {
            return toAjax(cookDishesTypeService.insertCookDishesType(cookDishesType));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 修改菜品类型信息
     */
    @ApiOperation(value = "修改菜品类型信息")
    @SysLog(title = "菜品类型信息", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改菜品类型信息")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody CookDishesType cookDishesType) {
        try {
            return toAjax(cookDishesTypeService.updateCookDishesType(cookDishesType));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 删除菜品类型信息
     */
    @ApiOperation(value = "删除菜品类型信息")
    @SysLog(title = "菜品类型信息", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除菜品类型信息")
	@PostMapping("/del/{dishesTypeIds}")
    public AjaxResult remove(@PathVariable Long[] dishesTypeIds) {
        return toAjax(cookDishesTypeService.deleteCookDishesTypeByDishesTypeIds(dishesTypeIds));
    }
}
