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

import cn.hutool.core.util.ObjectUtil;
import com.bonus.canteen.core.menu.dto.*;
import com.bonus.canteen.core.menu.service.MenuRecipeService;
import com.bonus.canteen.core.menu.vo.*;
import com.bonus.canteen.core.nutrition.api.NutritionDeviceApi;
import com.bonus.canteen.core.nutrition.device.dto.PersonalNutritionAnalyseDTO;
import com.bonus.canteen.core.nutrition.device.vo.PersonalNutritionAnalyseVO;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.houqin.i18n.I18n;
import com.bonus.common.houqin.utils.LeBeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping({"/api/v1/android/menurecipe"})
@Api(
   value = "androidmenurecipe",
   tags = {"pfy_安卓菜谱"}
)
public class AndroidRecipeController {
   private static final Logger log = LoggerFactory.getLogger(AndroidRecipeController.class);
   @Lazy
   @Autowired
   private MenuRecipeService menuRecipeService;
   @Autowired
   private NutritionDeviceApi nutritionDeviceApi;

//   //@RequiresGuest
   @GetMapping({"/detail"})
   @ApiOperation("根据菜谱id获取菜谱详情")
   public AjaxResult getAndroidRecipeDetail(String content) {
      List<AndroidRecipeDetailVO> recipeDetailVOList = this.menuRecipeService.getAndroidRecipeDetail(content);
      return AjaxResult.success(recipeDetailVOList);
   }

   @ApiOperation("安卓餐台获取全量餐品")
   @GetMapping({"/production/machine/detail"})
//   //@RequiresGuest
   public AjaxResult getProductionMachineRecipe() {
      List<AndroidRecipeTypeDetailVO> resultList = this.menuRecipeService.getProductionMachineRecipe();
      return AjaxResult.success(resultList);
   }

   @PostMapping({"/diningtable/all/detail"})
//   //@RequiresGuest
   @ApiOperation("安卓餐台需要全部的菜品套餐商品")
   public AjaxResult getDiningTableAllRecipe() {
      List<AndroidRecipeTypeDetailVO> androidRecipeTypeDetailVOList = this.menuRecipeService.getProductionMachineRecipe();
      return AjaxResult.success(androidRecipeTypeDetailVOList);
   }

   @PostMapping({"/heart/beat"})
//   //@RequiresGuest
   @ApiOperation("定时获取心跳包(电子菜排)")
   public AjaxResult getHeartBeat(@RequestBody @Valid MenuHeartBeatDTO content) {
      MenuHeartBeatVO result = this.menuRecipeService.getHeartBeat(content);
      return AjaxResult.success(result);
   }

   @PostMapping({"/ele/dish/row/recipe"})
//   //@RequiresGuest
   @ApiOperation("设备获取菜谱信息(电子菜排)")
   public AjaxResult getEleDishRowRecipe(@RequestBody @Valid MenuEleDishRowRecipeDTO content) {
      List<MenuEleDishRowRecipeVO> resultList = this.menuRecipeService.getEleDishRowRecipe(content);
      return AjaxResult.success(resultList);
   }

   @PostMapping({"/personal/nutrition/analyse"})
   //@RequiresGuest
   @ApiOperation("个人营养分析(自助查询机)")
   public AjaxResult getPersonalNutritionAnalyse(@RequestBody @Valid PersonalNutritionAnalyseDTO content) {
      PersonalNutritionAnalyseVO personalNutritionAnalyse = this.nutritionDeviceApi.getPersonalNutritionAnalyse(LeBeanUtil.copyCreateProperties(content, PersonalNutritionAnalyseDTO.class));
      return AjaxResult.success(LeBeanUtil.copyCreateProperties(personalNutritionAnalyse, PersonalNutritionAnalyseVO.class));
   }

   @PostMapping({"/personal/diet/record"})
   //@RequiresGuest
   @ApiOperation("个人饮食纪录(自助查询机)")
   public AjaxResult getPersonalDietRecord(@RequestBody @Valid PersonalDietRecordDTO content) {
      List<PersonalDietRecordVO> resultList = this.menuRecipeService.getPersonalDietRecord(content);
      return AjaxResult.success(resultList);
   }

   @PostMapping({"/all/product/recipe"})
   //@RequiresGuest
   @ApiOperation("获取所有出品机绑定菜谱详情(自助查询机)")
   public AjaxResult getAllProductsRecipe(@RequestBody @Valid AndroidAllProductsRecipeDTO content) {
      List<AndroidAllProductsRecipeVO> resultList = this.menuRecipeService.getAllProductsRecipe(content);
      return AjaxResult.success(resultList);
   }

   @PostMapping({"/all/shopstall/recipe/detail"})
   //@RequiresGuest
   @ApiOperation("获取绑定的多档口菜谱信息(点餐机)")
   public AjaxResult getAndroidAllRecipe(@RequestHeader("machine-sn") String machineSn,
                                         @RequestBody @Valid MenuAndroidAllRecipeDTO content) {
      List<AndroidRecipeDetailThreeVO> resultList = this.menuRecipeService.getAndroidAllRecipe(content, machineSn);
      return AjaxResult.success(resultList);
   }

   @PostMapping({"/recipe/info"})
   //@RequiresGuest
   @ApiOperation("根据菜谱ID获取菜谱相关信息")
   public AjaxResult getRecipeInfoByRecipeId(@RequestBody Long recipeId) {
      if (ObjectUtil.isEmpty(recipeId)) {
         throw new ServiceException(I18n.getMessage("menu_recipe_id_null"));
      } else {
         AppletMenuRecipeCanteenVO resultList = this.menuRecipeService.getRecipeInfoByRecipeId(recipeId);
         return AjaxResult.success(resultList);
      }
   }

   @PostMapping({"/add/recipe/dishes"})
   //@RequiresGuest
   @ApiOperation("设备增加菜品菜谱信息")
   public AjaxResult androidAddRecipeDishes(@RequestBody @Valid AndroidAddRecipeDishesDTO content) {
      this.menuRecipeService.androidAddRecipeDishes(content);
      return AjaxResult.success();
   }

   @PostMapping({"/get/recipe/detail/by/id"})
   //@RequiresGuest
   @ApiOperation("设备获取指定菜谱的详情(手持机)")
   public AjaxResult androidGetRecipeDishes(@RequestBody @Valid AndroidGetRecipeDishesDTO content) {
      List<AndroidGetRecipeDishesVO> resultList = this.menuRecipeService.androidGetRecipeDishes(content);
      return AjaxResult.success(resultList);
   }

   @PostMapping({"/get-recipe-list/by-shop"})
   @ApiOperation("获取菜谱列表(切菜平板)")
   public List<AndroidGetRecipeByShopVO> androidGetRecipeListByShop(@RequestBody AndroidGetRecipeByShopDTO content) {
      return this.menuRecipeService.androidGetRecipeListByShop(content);
   }

   @PostMapping({"/remove/recipe/dishes"})
   @ApiOperation("设备删除菜品菜谱信息")
   public AjaxResult androidRemoveRecipeDishes(@RequestBody @Valid AndroidRemoveRecipeDishesDTO content) {
      this.menuRecipeService.androidRemoveRecipeDishes(content);
      return AjaxResult.success();
   }

   @PostMapping({"/production/recipe-detail"})
   @ApiOperation("出品机获取菜谱详情信息")
   public List<AndroidProductionRecipeVO> getProductionRecipeDetail(@RequestBody @Valid AndroidProductionRecipeDTO content) {
      return this.menuRecipeService.getProductionRecipeDetail(content);
   }
}
