package com.usky.cdi.controller;

import com.usky.cdi.service.impl.AlarmDataTransferService;
import com.usky.cdi.service.vo.alarm.AlarmMessage1VO;
import com.usky.cdi.service.vo.alarm.AlarmMessage2VO;
import com.usky.cdi.service.vo.alarm.AlarmMessage3VO;
import com.usky.cdi.service.vo.alarm.AlarmMessageVO;
import com.usky.cdi.service.vo.base.EngineeringBaseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础类数据传输控制器
 * 提供基础类数据上报的接口
 *
 * @author han
 * @date 2025/12/08
 */
@Slf4j
@RestController
@RequestMapping("/api/alarm")
@ConditionalOnProperty(prefix = "mqtt", value = {"enabled"}, havingValue = "true")
public class AlarmDataController {
    @Autowired
    private AlarmDataTransferService alarmDataTransferService;
    /**
     * 上报人防工程基础信息
     */
    @PostMapping("/alarmMessage")
    public String sendAlarmMessage(@RequestBody AlarmMessageVO vo) {
        boolean success = alarmDataTransferService.sendAlarmMessage(vo);
        return success ? "上报成功" : "上报失败";
    }

    /**
     * 上报人防工程基础信息
     */
    @PostMapping("/alarmMessage1")
    public String sendAlarmMessage1(@RequestBody AlarmMessage1VO vo) {
        boolean success = alarmDataTransferService.sendAlarmMessage1(vo);
        return success ? "上报成功" : "上报失败";
    }

    /**
     * 上报倾斜、位移、裂缝监测事件
     */
    @PostMapping("/alarmMessage2")
    public String sendAlarmMessage2(@RequestBody AlarmMessage2VO vo) {
        boolean success = alarmDataTransferService.sendAlarmMessage2(vo);
        return success ? "上报成功" : "上报失败";
    }

    @PostMapping("/alarmMessage3")
    public String sendAlarmMessage3(@RequestBody AlarmMessage3VO vo) {
        boolean success = alarmDataTransferService.sendEngineeringBase(vo);
        return success ? "上报成功" : "上报失败";
    }
}
