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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.menu.dto.MenuDishesCookAddDTO;
import com.bonus.canteen.core.menu.dto.MenuDishesCookEditDTO;
import com.bonus.canteen.core.menu.service.MenuDishesCookService;
import com.bonus.canteen.core.menu.vo.MenuDishesCookPageVO;
import com.bonus.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping({"/api/v1/menudishescook"})
@Api(
   value = "menudishescook",
   tags = {"pfy_菜品灶类信息管理"}
)
public class MenuDishesCookController {
   @Autowired
   @Lazy
   private MenuDishesCookService menuDishesCookService;

   @PostMapping({"/add"})
   @ApiOperation("新增菜品灶类信息")
   public AjaxResult addMenuDishesCook(@RequestBody @Valid MenuDishesCookAddDTO dto) {
      this.menuDishesCookService.addMenuDishesCook(dto);
      return AjaxResult.success();
   }

   @GetMapping({"/page"})
   @ApiOperation("分页获取菜品灶类信息")
   public AjaxResult getMenuDishesCookPage(String content) {
      Page<MenuDishesCookPageVO> resultPage = this.menuDishesCookService.getMenuDishesCookPage(content);
      return AjaxResult.success(resultPage);
   }

   @PostMapping({"/edit"})
   @ApiOperation("修改菜品灶类信息")
   public AjaxResult editMenuDishesCook(@RequestBody MenuDishesCookEditDTO dto) {
      this.menuDishesCookService.editMenuDishesCook(dto);
      return AjaxResult.success();
   }

   @PostMapping({"/remove/{cookId}"})
   @ApiOperation("删除菜品灶类信息")
   public AjaxResult removeByCookId(@PathVariable Long cookId) {
      this.menuDishesCookService.removeByMaterialId(cookId);
      return AjaxResult.success();
   }
}
