package com.jeeplus.psimanage.dishManage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.logging.annotation.ApiLog;
import com.jeeplus.logging.constant.enums.LogTypeEnum;
import com.jeeplus.psimanage.dishManage.domain.PsiDishLibrary;
import com.jeeplus.psimanage.dishManage.domain.PsiDishMenu;
import com.jeeplus.psimanage.dishManage.domain.PsiDishMenuDish;
import com.jeeplus.psimanage.dishManage.domain.PsiDishType;
import com.jeeplus.psimanage.dishManage.service.PsiDishMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 菜单管理
 */
@RestController
@Api(tags = "菜单管理")
@RequestMapping(value = "/psi/dishMenu")
public class PsiDishMenuController {

    @Resource
    private PsiDishMenuService service;

    @ApiOperation(value = "当前菜单菜品列表")
    @GetMapping("/list")
    public ResponseEntity<IPage<PsiDishMenuDish>> list(Page<PsiDishMenuDish> page, PsiDishMenuDish info) {
        return ResponseEntity.ok(service.list(page, info));
    }

    @ApiOperation(value = "历史菜单菜品列表")
    @GetMapping("/historyList")
    public ResponseEntity<IPage<PsiDishMenu>> historyList(Page<PsiDishMenu> page) {
        return ResponseEntity.ok(service.historyList(page));
    }

    @ApiOperation(value = "历史菜单菜品列表")
    @GetMapping("/historyDetailList")
    public ResponseEntity<IPage<PsiDishMenuDish>> historyDetailList(Page<PsiDishMenuDish> page,
                                                                    @RequestParam String menuId,
                                                                    PsiDishMenuDish info) {
        return ResponseEntity.ok(service.historyDetailList(page, menuId, info));
    }

    @ApiOperation(value = "可添加菜品列表")
    @GetMapping("/availableDishList")
    public ResponseEntity<IPage<PsiDishLibrary>> availableDishList(Page<PsiDishLibrary> page, PsiDishLibrary info) {
        return ResponseEntity.ok(service.availableDishList(page, info));
    }

    @ApiOperation(value = "点单菜品列表")
    @GetMapping("/orderDishList")
    public ResponseEntity<List<PsiDishLibrary>> orderDishList(@RequestParam(required = false) String typeId,
                                                              @RequestParam(required = false) String dishName) {
        return ResponseEntity.ok(service.orderDishList(typeId, dishName));
    }

    @ApiOperation(value = "点单分类列表")
    @GetMapping("/orderTypeList")
    public ResponseEntity<List<PsiDishType>> orderTypeList() {
        return ResponseEntity.ok(service.orderTypeList());
    }

    @ApiLog(value = "添加菜单菜品", type = LogTypeEnum.SAVE)
    @ApiOperation(value = "添加菜单菜品")
    @PostMapping("/addDishes")
    public ResponseEntity<String> addDishes(@RequestBody List<String> dishIds) {
        return ResponseEntity.ok(service.addDishes(dishIds));
    }

    @ApiLog(value = "保存菜单菜品", type = LogTypeEnum.SAVE)
    @ApiOperation(value = "保存菜单菜品")
    @PostMapping("/saveDishes")
    public ResponseEntity<String> saveDishes(@RequestBody List<String> dishIds) {
        return ResponseEntity.ok(service.saveDishes(dishIds));
    }

    @ApiLog(value = "调整菜单价格", type = LogTypeEnum.SAVE)
    @ApiOperation(value = "调整菜单价格")
    @PostMapping("/updatePrice")
    public ResponseEntity<String> updatePrice(@RequestBody PsiDishMenuDish info) {
        return ResponseEntity.ok(service.updatePrice(info));
    }

    @ApiLog(value = "删除菜单菜品", type = LogTypeEnum.SAVE)
    @ApiOperation(value = "删除菜单菜品")
    @DeleteMapping("/delete")
    public ResponseEntity<String> delete(@RequestParam String ids) {
        return ResponseEntity.ok(service.deleteByIds(ids));
    }

    @ApiLog(value = "更新菜单", type = LogTypeEnum.SAVE)
    @ApiOperation(value = "更新菜单")
    @PostMapping("/updateMenu")
    public ResponseEntity<String> updateMenu(@RequestBody List<String> dishIds) {
        return ResponseEntity.ok(service.updateMenu(dishIds));
    }
}
