#include "acoustic_analyzer/ros/threat_publisher.h"
#include <acoustic_analyzer/AcousticThreat.h>

namespace acoustic {

ThreatPublisher::ThreatPublisher(ros::NodeHandle& nh) {
    pub_ = nh.advertise<acoustic_analyzer::AcousticThreatArray>("/acoustic/threats", 10);
}

void ThreatPublisher::publish(const std::vector<TrackedThreat>& threats) {
    acoustic_analyzer::AcousticThreatArray msg;
    msg.header.stamp = ros::Time::now();
    msg.header.frame_id = "acoustic_array";

    for (const auto& t : threats) {
        acoustic_analyzer::AcousticThreat threat_msg;
        threat_msg.threat_id = t.threat_id;
        threat_msg.sound_type = t.sound_type;
        threat_msg.confidence = t.confidence;
        threat_msg.azimuth = t.azimuth;
        threat_msg.elevation = t.elevation;
        threat_msg.distance = t.distance;
        threat_msg.distance_confidence = t.distance_confidence;
        msg.threats.push_back(threat_msg);
    }

    pub_.publish(msg);
}

} // namespace acoustic
