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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.menu.dto.MenuDishesTypeAddDTO;
import com.bonus.canteen.core.menu.dto.MenuDishesTypeEditDTO;
import com.bonus.canteen.core.menu.dto.MenuTypeDishesDTO;
import com.bonus.canteen.core.menu.service.MenuDishesTypeService;
import com.bonus.canteen.core.menu.vo.MenuDishesTypeAllVO;
import com.bonus.canteen.core.menu.vo.MenuDishesTypePageVO;
import com.bonus.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping({"/api/v1/menudishestype"})
@Api(
   value = "menudishestype",
   tags = {"pfy_菜品类型信息管理"}
)
public class MenuDishesTypeController {
   @Resource
   @Lazy
   private MenuDishesTypeService menuDishesTypeService;

   @PostMapping({"/add"})
   @ApiOperation("新增菜品类型信息")
   public AjaxResult addMenuDishesType(@RequestBody @Valid MenuDishesTypeAddDTO dto) {
      this.menuDishesTypeService.addMenuDishesType(dto);
      return AjaxResult.success();
   }

   @GetMapping({"/page"})
   @ApiOperation("分页获取菜品类型信息")
   public AjaxResult getMenuDishesTypePage(String dto) {
      Page<MenuDishesTypePageVO> resultPage = this.menuDishesTypeService.getMenuDishesTypePage(dto);
      return AjaxResult.success(resultPage);
   }

   @PostMapping({"/edit"})
   @ApiOperation("修改菜品类型信息")
   public AjaxResult editMenuDishesType(@RequestBody @Valid MenuDishesTypeEditDTO dto) {
      this.menuDishesTypeService.editMenuDishesType(dto);
      return AjaxResult.success();
   }

   @PostMapping({"/remove/{typeId}"})
   @ApiOperation("删除菜品类型信息")
   public AjaxResult removeByTypeId(@PathVariable Long typeId) {
      this.menuDishesTypeService.removeByTypeId(typeId);
      return AjaxResult.success();
   }

   @PostMapping({"/data/recovery"})
   @ApiOperation("菜品类型错误数据修复")
   public AjaxResult dateRecoveryMenuDishesType() {
      this.menuDishesTypeService.dateRecoveryMenuDishesType();
      return AjaxResult.success();
   }

   @PostMapping({"/all/list"})
   @ApiOperation("获取所有菜品类别")
   public AjaxResult getAllMenuDishesTypeList() {
      List<MenuDishesTypeAllVO> resultList = this.menuDishesTypeService.getAllMenuDishesTypeList();
      return AjaxResult.success(resultList);
   }

   @PostMapping({"/all/use/list"})
   @ApiOperation("获取正在使用的所有菜品类别")
   public AjaxResult getAllUseMenuDishesTypeList(@RequestBody MenuTypeDishesDTO dto) {
      List<MenuDishesTypeAllVO> resultList = this.menuDishesTypeService.getAllUseMenuDishesTypeList(dto);
      return AjaxResult.success(resultList);
   }
}
