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

import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.allocation.canteen.business.AllocCanteenBusiness;
import com.bonus.canteen.core.allocation.canteen.dto.AllocAreaAddDTO;
import com.bonus.canteen.core.allocation.canteen.dto.AllocAreaUpdateDTO;
import com.bonus.canteen.core.allocation.canteen.param.AllocAreaParam;
import com.bonus.canteen.core.allocation.canteen.service.AllocAreaService;
import com.bonus.canteen.core.allocation.canteen.vo.AllocAreaVO;
import com.bonus.common.core.web.domain.AjaxResult;
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 javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping({"/api/v2/alloc/area"})
@Api(
   tags = {"lsh_食堂区域控制器"}
)
public class AllocAreaController {
   private static final Logger log = LoggerFactory.getLogger(AllocAreaController.class);
   @Autowired
   @Lazy
   private AllocCanteenBusiness allocCanteenBusiness;
   @Autowired
   @Lazy
   private AllocAreaService allocAreaService;

   @ApiOperation("分页查询区域列表")
   @PostMapping({"/page"})
//   @RequiresGuest
   public Page<AllocAreaVO> pageArea(@RequestBody AllocAreaParam request) {
      return this.allocAreaService.pageArea(request);
   }

   @ApiOperation("系统区域树")
   @PostMapping({"/system/tree"})
   public List<Tree<Long>> getSystemAreaTree() {
      return this.allocAreaService.getSystemAreaTree();
   }

   @ApiOperation("系统区域权限树")
   @PostMapping({"/system-auth/tree"})
   public List<Tree<Long>> getSystemAuthAreaTree() {
      return this.allocAreaService.getSystemAuthAreaTree();
   }

   @ApiOperation("根据区域id，查询区域名称")
   @PostMapping({"/get-area-name"})
//   @RequiresGuest
   public AjaxResult getAreaName(@RequestBody Map<String, Object> request) {
      Long areaId = Long.valueOf((String) request.get("areaId"));
      return AjaxResult.success(this.allocAreaService.getAreaName(areaId));
   }

   @ApiOperation("新增区域")
   @PostMapping({"/add"})
//   @RequiresGuest
   public void addArea(@RequestBody @Valid AllocAreaAddDTO request) {
      this.allocAreaService.addArea(request);
   }

   @ApiOperation("修改区域")
   @PostMapping({"/update"})
//   @RequiresGuest
   public void updateArea(@RequestBody @Valid AllocAreaUpdateDTO request) {
      this.allocAreaService.updateArea(request);
   }

   @ApiOperation("删除区域")
   @PostMapping({"/remove"})
//   @RequiresGuest
   public void removeArea(@RequestBody Map<String, Object> request) {
      Long areaId = Long.valueOf((String) request.get("areaId"));
      this.allocCanteenBusiness.removeArea(areaId);
   }
}
