package com.fuint.module.backendApi.controller;

import com.fuint.common.dto.AccountInfo;
import com.fuint.common.dto.IngredientDto;
import com.fuint.common.util.TokenUtil;
import com.fuint.common.vo.IngredientVo;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.PageResult;
import com.fuint.framework.web.ResponseObject;
import com.fuint.common.Constants;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.service.IngredientService;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.repository.model.MtIngredient;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 菜品配料表管理类controller
 *
 * Created by pzg
 * CopyRight https://www.fuint.cn
 */
@Api(tags="管理端-菜品配料表相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/backendApi/ingredient")
public class BackendIngredientController extends BaseController {

    /**
     * 菜品配料表服务接口
     */
    private IngredientService ingredientService;

    /**
     * 菜品配料表列表查询
     *
     * @param  request HttpServletRequest对象
     * @return 菜品配料表列表
     */
    @ApiOperation(value = "菜品配料表列表查询")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('ingredient:list')")
    public ResponseObject list(HttpServletRequest request, IngredientDto ingredientDto) throws BusinessCheckException {

        PageResult<IngredientVo> result = ingredientService.queryIngredientPageList(ingredientDto);

        return getSuccessResult(result);
    }

    /**
     * 更新菜品配料表状态
     *
     * @return
     */
    @ApiOperation(value = "更新菜品配料表状态")
    @RequestMapping(value = "/updateIngredient", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('ingredient:edit')")
    public ResponseObject updateStatus(HttpServletRequest request, @RequestBody IngredientDto ingredientDto) throws BusinessCheckException {

        ingredientService.updateIngredient(ingredientDto);

        return getSuccessResult(true);
    }

    /**
     * 更删除菜品配料表
     *
     * @return
     */
    @ApiOperation(value = "删除菜品配料表状态")
    @RequestMapping(value = "/deleteIngredientById/{id}", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('ingredient:edit')")
    public ResponseObject deleteIngredientById(HttpServletRequest request, @PathVariable("id") Long id) throws BusinessCheckException {

        ingredientService.deleteIngredientById(id);

        return getSuccessResult(true);
    }

    /**
     * 为菜品添加配料
     *
     * @param request HttpServletRequest对象
     * @return
     */
    @ApiOperation(value = "为菜品添加配料")
    @RequestMapping(value = "/addIngredientForGoods", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('ingredient:add')")
    public ResponseObject addIngredientForGoods(HttpServletRequest request, @RequestBody List<IngredientDto > ingredientDtoList) throws BusinessCheckException {

        ingredientService.addIngredientForGoods(ingredientDtoList);

        return getSuccessResult(true);
    }

    /**
     * 获取菜品配料表详情
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "获取菜品配料表详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('ingredient:list')")
    public ResponseObject info(HttpServletRequest request, @PathVariable("id") Long id) throws BusinessCheckException {

        IngredientVo result = ingredientService.queryIngredientById(Long.valueOf(id));

        return getSuccessResult(result);
    }
}
