package org.springblade.third.iotdevice.open;


import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import org.springblade.community.feign.IResidentialClient;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.device.feign.*;
import org.springblade.sms.service.IPepNoticeService;
import org.springblade.system.expand.feign.IOrgPositionClient;
import org.springblade.system.user.feign.IUserClient;
import org.springblade.third.iotdevice.service.IDataReportStrategy;
import org.springblade.third.iotdevice.service.impl.*;
import org.springblade.workorder.deviceorder.feign.IDeviceOrderClient;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author lidexi
 * @date 2021/5/27 17:29
 */
@RestController
@RequestMapping("/open/aep")
@AllArgsConstructor
public class AepSubScribeController {

	private final AepSubScribeServiceImpl aepSubScribeServiceImpl;
	private final BladeLogger bladeLogger;
	private final IIotDeviceClient iotDeviceClient;
	private final IIotDeviceHeartbeatClient iotDeviceHeartbeatClient;
	private final IIotAlarmClient iotAlarmClient;
	private final IIotAlarmGroupUserClient iotAlarmGroupUserClient;
	private final IIotAlarmGroupClient iotAlarmGroupClient;
	private final IDeviceOrderClient deviceOrderClient;
	private final OrderGenerateUtilService orderGenerateUtilService;
	private final IResidentialClient residentialClient;
	private final IPepNoticeService pepNoticeService;
	private final IOrgPositionClient orgPositionClient;
	private final RedisTemplate<String,String> redisTemplate;
	private final IUserClient userClient;

	@PostMapping("/dataReport/{profile}")
	public void DataReport(@RequestBody Map<String, Object> map, @PathVariable("profile") String profile) {
		bladeLogger.info("dataReport", JSONUtil.toJsonStr(map));
		IDataReportStrategy dataReportStrategy = "profile".equals(profile) ?
			new ProfileDataReportStrategy(iotDeviceClient,iotDeviceHeartbeatClient,iotAlarmClient,deviceOrderClient,
				orderGenerateUtilService,residentialClient,iotAlarmGroupClient,iotAlarmGroupUserClient,pepNoticeService,
				userClient,redisTemplate,orgPositionClient) :
			new NoProfileDataReportStrategy(iotDeviceClient,iotDeviceHeartbeatClient,iotAlarmClient,deviceOrderClient,
				orderGenerateUtilService,residentialClient,iotAlarmGroupClient,iotAlarmGroupUserClient,pepNoticeService,
				userClient,redisTemplate,orgPositionClient);
		aepSubScribeServiceImpl.setDataReportContext(new DataReportContext(dataReportStrategy)).setIotDeviceClient(iotDeviceClient);
		aepSubScribeServiceImpl.dataReport(map);
	}


}
