package com.bonus.canteen.core.drp.api;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import java.lang.invoke.SerializedLambda;
import java.util.List;
import java.util.Map;
import com.bonus.canteen.core.device.api.DeviceApi;
import com.bonus.canteen.core.device.manage.model.DeviceBind;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.houqin.i18n.I18n;
import com.bonus.common.houqin.utils.HeaderFetchUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

@Service
public class DrpAuthorityApi {
   public static final String DRP_DEVICE_NOT_BIND_AREA = "drp.device-not-bind-area";
   @Autowired
   @Lazy
   private DeviceApi deviceApi;


   public Long getAreaIdByDeviceSn(Map<String, String> headers) {
      try {
         String machineSn = HeaderFetchUtil.getMachineSn(headers);
         Assert.notBlank(machineSn, () -> {
            return new ServiceException(I18n.getMessage("drp.device-sn-not-null", new Object[0]));
         });
         return ((DeviceBind)this.deviceApi.listBindByDeviceSn(machineSn).get(0)).getAreaId();
      } catch (Exception var3) {
         throw new ServiceException(I18n.getMessage("drp.device-not-bind-area", new Object[0]));
      }
   }
}
