package com.sptg.iot.biz.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.iot.api.beans.ApiResultBean;
import com.sptg.iot.api.dto.AlarmNoticeDto;
import com.sptg.iot.api.dto.IotAlarmDto;
import com.sptg.iot.api.dto.IotSmsSendDto;
import com.sptg.iot.api.entity.IotAlarm;
import com.sptg.iot.api.entity.IotAuthentication;
import com.sptg.iot.api.entity.IotDevice;
import com.sptg.iot.api.entity.IotSysConf;
import com.sptg.iot.api.feigns.IotAlarmFeign;
import com.sptg.iot.api.util.IotHttpUtil;
import com.sptg.iot.biz.service.IotAlarmServiceInterface;
import com.sptg.iot.biz.service.IotApiLogServiceInterface;
import com.sptg.iot.biz.service.IotAuthServiceInterface;
import com.sptg.iot.biz.service.IotSysConfServiceInterface;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author zwx
 * @create 2020/10/20 9:28
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class IotAlarmController implements IotAlarmFeign {

    private final IotAlarmServiceInterface iotAlarmServiceInterface;

    @Override
    @PostMapping(value = "/iot/alarm/list")
    public ResultBean<Page<IotAlarm>> showIotAlarmList(@RequestBody IotAlarmDto iotAlarmDto) {
        ResultBean<Page<IotAlarm>> pageResultBean = this.iotAlarmServiceInterface.showIotAlarmList(iotAlarmDto);
        return pageResultBean;
    }

    @Override
    @PostMapping(value = "/iot/alarm/pagingQuery")
    public ResultBean<Page<IotAlarm>> pagingQuery(@RequestBody IotAlarmDto IotAlarmDto) {
        return this.iotAlarmServiceInterface.pagingQuery(IotAlarmDto);
    }

    /**
     * 功能描述:同步告警列表
     * @param iotAlarmDto
     * @return
     */
    @Override
    @PostMapping(value = "/iot/alarm/sync/list")
    public ResultBean<String> syncIotAlarmList(@RequestBody IotAlarmDto iotAlarmDto) {
        ResultBean<String> resultBean = this.iotAlarmServiceInterface.syncIotAlarmList(iotAlarmDto);
        return resultBean;
    }

    /**
     * 功能描述:同步告警详情（单个）
     * @param iotAlarmDto
     * @return
     */
    @Override
    @PostMapping(value = "/iot/alarm/sync/detail/one")
    public ResultBean<String> syncIotAlarmDetailOne(@RequestBody IotAlarmDto iotAlarmDto) {
        ResultBean<String> resultBean = this.iotAlarmServiceInterface.syncIotAlarmDetailOne(iotAlarmDto);
        return resultBean;
    }

    /**
     * 功能描述:同步告警详情（批量）
     * @param iotAlarmDtoList
     * @return
     */
    @Override
    @PostMapping(value = "/iot/alarm/sync/detail/batch")
    public ResultBean<String> syncIotAlarmDetailBatch(@RequestBody List<IotAlarmDto> iotAlarmDtoList) {
        ResultBean<String> resultBean = this.iotAlarmServiceInterface.syncIotAlarmDetailBatch(iotAlarmDtoList);
        return resultBean;
    }

    /**
     * 功能描述:同步告警详情（全量）
     * @param iotAlarmDto
     * @return
     */
    @Override
    @PostMapping(value = "/iot/alarm/sync/detail/all")
    public ResultBean<String> syncIotAlarmDetailAll(@RequestBody IotAlarmDto iotAlarmDto) {
        ResultBean<String> resultBean = this.iotAlarmServiceInterface.syncIotAlarmDetailAll(iotAlarmDto);
        return resultBean;
    }


    @Override
    @GetMapping(value = "/iot/alarm/getByAlarmId/{alarmId}")
    public IotAlarm getIotAlarmByAlarmId(@PathVariable(value = "alarmId") String alarmId) {
        IotAlarm iotAlarm = this.iotAlarmServiceInterface.getIotAlarmByAlarmId(alarmId);
        return iotAlarm;
    }

    @Override
    @GetMapping(value = "/iot/alarm/getIotAlarmById/{id}")
    public IotAlarm getIotAlarmById(@PathVariable(value = "id") Long id) {
        IotAlarm iotAlarm = this.iotAlarmServiceInterface.getIotAlarmById(id);
        return iotAlarm;
    }

    @Override
    @PostMapping(value = "/iot/alarm/notice")
    public ResultBean<String> alarmNotice(@RequestBody List<AlarmNoticeDto> alarmNoticeDtoList) {
        this.iotAlarmServiceInterface.alarmNotice(alarmNoticeDtoList);
        return ResultBean.ok();
    }

    @Override
    @PostMapping(value = "/iot/alarm/add")
    public ResultBean<Boolean> addAlarm(@RequestBody IotAlarmDto iotAlarmDto) {
        boolean insert = this.iotAlarmServiceInterface.insert(iotAlarmDto);
        return new ResultBean<>(ResultEnum.SUCCESS, insert);
    }

    @Override
    @PostMapping(value = "/iot/alarm/sendSms")
    public ResultBean<Boolean> alarmSendSms(@RequestBody IotSmsSendDto iotSmsSendDto) {
        ResultBean<Boolean> resultBean = this.iotAlarmServiceInterface.alarmSendSms(iotSmsSendDto);
        return resultBean;
    }
}
