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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.marketing.dto.MktEffectiveAddDTO;
import com.bonus.canteen.core.marketing.dto.MktEffectiveEditDTO;
import com.bonus.canteen.core.marketing.service.MktEffectiveService;
import com.bonus.canteen.core.drp.vo.DrpWarehouseAllVO;
import com.bonus.canteen.core.marketing.vo.MktEffectiveByEffIdVO;
import com.bonus.canteen.core.marketing.vo.MktEffectivePageVO;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.houqin.i18n.I18n;
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;

/** @deprecated */
@Deprecated
@RestController
@RequestMapping({"/api/v1/mkteffective"})
@Api(
   value = "营销中心/数据权限",
   tags = {"营销中心/数据权限"}
)
public class MktEffectiveController {
   private static final Logger log = LoggerFactory.getLogger(MktEffectiveController.class);
   @Autowired
   @Lazy
   private MktEffectiveService mktEffectiveService;

   @PostMapping({"/add"})
   @ApiOperation("新增生效范围")
   public AjaxResult addMktEffective(@RequestBody @Valid MktEffectiveAddDTO dto) {
      this.mktEffectiveService.addMktEffective(dto);
      return AjaxResult.success();
   }

   @GetMapping({"/page"})
   @ApiOperation("分页获取生效范围")
   public AjaxResult getMktEffectivePage(String content) {
      Page<MktEffectivePageVO> effectivePage = this.mktEffectiveService.getMktEffectivePage(content);
      return AjaxResult.success(effectivePage);
   }

   @ApiOperation("修改生效范围信息")
   @PutMapping({"/edit"})
   public AjaxResult editMktEffective(@RequestBody MktEffectiveEditDTO dto) {
      if (dto == null) {
         log.error("***编辑时段定额获取参数为空*********************");
         return AjaxResult.error("参数解析错误,请使用正确的途径访问,否则你就惨了...");
      } else {
         this.mktEffectiveService.editMktEffective(dto);
         return AjaxResult.success();
      }
   }

   @ApiOperation("删除生效范围信息")
   @DeleteMapping({"/remove/{effId}"})
   public AjaxResult removeEffId(@PathVariable Long effId) {
      if (effId == null) {
         log.error("***传入的范围id为空,不能删除****************");
         return AjaxResult.error(I18n.getMessage("mkt_rule_error_param", new Object[0]));
      } else {
         throw new ServiceException(I18n.getMessage("mkt_rule_no_del", new Object[0]));
      }
   }

   @GetMapping({"/detail/{effId}"})
   @ApiOperation("获取指定范围id的信息")
   public AjaxResult getMktEffectiveByEffId(@PathVariable Long effId) {
      MktEffectiveByEffIdVO effective = this.mktEffectiveService.getMktEffectiveByEffId(effId);
      return AjaxResult.success(effective);
   }

   @PostMapping({"/all"})
   @ApiOperation("获取仓库信息")
   public AjaxResult getDrpWarehouseAll() {
      List<DrpWarehouseAllVO> resultList = this.mktEffectiveService.getAllDrpWarehouse();
      return AjaxResult.success(resultList);
   }

   @ApiOperation("系统仓库树")
   @GetMapping({"/warehouse/system/list"})
   public List<DrpWarehouseAllVO> getSystemWarehouse() {
      return this.mktEffectiveService.getAllDrpWarehouse();
   }

   @ApiOperation("商户权限仓库")
   @GetMapping({"/warehouse/tenant/list"})
   public List<DrpWarehouseAllVO> getTenantWarehouse() {
      return this.mktEffectiveService.getTenantWarehouse();
   }
}
