package cn.iocoder.yudao.module.system.controller.admin.restaurant;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.dal.dataobject.restaurant.FoodCategoryDO;
import cn.iocoder.yudao.module.system.service.restaurant.FoodCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 菜品分类")
@RestController
@RequestMapping("/system/foodCategory")
@Validated
public class FoodCategoryController {

    @Resource
    private FoodCategoryService foodCategoryService;

    @PostMapping("/create")
    @Operation(summary = "创建菜品分类")
    public CommonResult<Boolean> createFoodCategory(@Valid @RequestBody FoodCategoryDO createReqVO) {
        foodCategoryService.createFoodCategory(createReqVO);
        return success(true);
    }

    @PutMapping("/update")
    @Operation(summary = "更新菜品分类")
    public CommonResult<Boolean> updateFoodCategory(@Valid @RequestBody FoodCategoryDO updateReqVO) {
        foodCategoryService.updateFoodCategory(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除菜品分类")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteFoodCategory(@RequestParam("id") Long id) {
        foodCategoryService.deleteFoodCategory(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得菜品分类详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<FoodCategoryDO> getFoodCategory(@RequestParam("id") Long id) {
        return success(foodCategoryService.getFoodCategory(id));
    }


    @GetMapping("/getTree")
    @Operation(summary = "树形结构分类列表")
    public CommonResult<List<FoodCategoryDO>>  getTree(@RequestParam("restaurantId") Long restaurantId){
        return success(foodCategoryService.getTree(restaurantId));
    }


//
//    @GetMapping("/page")
//    @Operation(summary = "获得菜品分类分页")
//    @PreAuthorize("@ss.hasPermission('system:food-category:query')")
//    public CommonResult<PageResult<FoodCategoryRespVO>> getFoodCategoryPage(@Valid FoodCategoryPageReqVO pageReqVO) {
//        PageResult<FoodCategoryDO> pageResult = foodCategoryService.getFoodCategoryPage(pageReqVO);
//        return success(BeanUtils.toBean(pageResult, FoodCategoryRespVO.class));
//    }
//
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出菜品分类 Excel")
//    @PreAuthorize("@ss.hasPermission('system:food-category:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportFoodCategoryExcel(@Valid FoodCategoryPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<FoodCategoryDO> list = foodCategoryService.getFoodCategoryPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "菜品分类.xls", "数据", FoodCategoryRespVO.class,
//                        BeanUtils.toBean(list, FoodCategoryRespVO.class));
//    }

}