package com.bonus.core.device.manage.controller.applet;

import cn.hutool.core.util.ObjectUtil;
import com.bonus.core.common.base.BaseController;
import com.bonus.core.common.enums.SourceTypeEnum;
import com.bonus.core.device.manage.service.DeviceInfoService;
import com.bonus.core.device.manage.controller.deprecated.vo.*;
import com.bonus.core.device.manage.model.*;
import com.bonus.core.device.manage.dto.*;
import com.bonus.core.device.manage.vo.*;
import com.bonus.core.device.utils.DeviceDtoConverter;
import com.bonus.encrypt.RequiresGuest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping({"/api/v1/applet/machine"})
@Api(
   value = "小程序设备",
   tags = {"小程序设备"}
)
public class AppletMachineConterooler extends BaseController {
   @Autowired
   @Lazy
   DeviceInfoService deviceInfoService;

   @GetMapping({"/getCounterBypage"})
   @RequiresGuest
   @ApiOperation("根据商户id 取餐柜类型获取取餐柜生鲜柜")
   public List<MachineCounterVO> getMachineCounterByPage(@RequestHeader Map<String, String> headers, String content) {
      this.logger.info("获取商户所有取餐柜/生鲜柜信息:商户id:{}", this.getMerchantIdByHeaders(headers));
      Integer deviceType = SourceTypeEnum.MEAL_LOCKER.getKey();
      if (ObjectUtil.isNotNull(content) && !"{}".equals(content)) {
         deviceType = Integer.parseInt(content);
      }

      List<DeviceInfo> deviceList = this.deviceInfoService.list((new DeviceSearchDTO()).setDeviceType(deviceType));
      List<DeviceFullInfoVO> deviceFullInfoVOList = this.deviceInfoService.fillFullVo(deviceList);
      return DeviceDtoConverter.toMachineCounterVO(deviceFullInfoVOList);
   }
}
