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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.supermarket.api.SupermarketApi;
import com.bonus.canteen.core.supermarket.dto.SupermarketInfoAddDTO;
import com.bonus.canteen.core.supermarket.dto.SupermarketInfoEditDTO;
import com.bonus.canteen.core.supermarket.dto.SupermarketInfoPageDTO;
import com.bonus.canteen.core.supermarket.service.SupermarketInfoService;
import com.bonus.canteen.core.supermarket.vo.SupermarketInfoPageVO;
import com.bonus.canteen.core.supermarket.vo.SupermarketTreeVO;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@RequestMapping({"/api/v1/basics-supermarket"})
@Api(
   tags = {"gyp-商超-超市管理"}
)
public class SupermarketInfoController {
   private static final Logger log = LoggerFactory.getLogger(SupermarketInfoController.class);
   @Autowired
   @Lazy
   private SupermarketInfoService supermarketInfoService;
   @Autowired
   @Lazy
   private SupermarketApi supermarketApi;

   @ApiOperation(
      value = "分页查询超市",
      notes = "分页查询超市"
   )
   @PostMapping({"/page-supermarket"})
   public Page<SupermarketInfoPageVO> pageSupermarket(@RequestBody SupermarketInfoPageDTO content) {
      return this.supermarketInfoService.pageSupermarket(content);
   }

   @ApiOperation(
      value = "新增超市",
      notes = "新增超市"
   )
   @PostMapping({"/insert-supermarket"})
   public void insertSupermarket(@RequestBody @Valid SupermarketInfoAddDTO content) {
      this.supermarketInfoService.insertSupermarket(content);
   }

   @ApiOperation(
      value = "修改超市",
      notes = "修改超市"
   )
   @PostMapping({"/edit-supermarket"})
   public void editSupermarket(@RequestBody @Valid SupermarketInfoEditDTO content) {
      this.supermarketInfoService.editSupermarket(content);
   }

   @ApiOperation(
      value = "删除超市",
      notes = "删除超市根据超市id"
   )
   @PostMapping({"/delete-supermarket"})
   public void deleteSupermarketById(@RequestBody Long content) {
      this.supermarketInfoService.deleteSupermarketById(content);
   }

   @PostMapping({"/supermarket-tree"})
   @ApiOperation("查询超市树")
   public List<SupermarketTreeVO> querySupermarketTree() {
      return this.supermarketInfoService.querySupermarketTree();
   }

   @PostMapping({"/if-relate-drp"})
   @ApiOperation("库存是否关联出入库")
   public Boolean ifRelateDrp(@RequestBody Long supermarketId) {
      return this.supermarketApi.ifRelateDrp(supermarketId);
   }
}
