use crate::data::hazard_def::HazardType;
use godot::prelude::*;

#[derive(GodotClass)]
#[class(base=Node)]
pub struct EventBus {
    base: Base<Node>,
}

#[godot_api]
impl INode for EventBus {
    fn init(base: Base<Node>) -> Self {
        Self { base }
    }
}

#[godot_api]
impl EventBus {
    #[signal]
    fn lift_effort_applied(strength: f32);

    #[signal]
    fn focus_released();

    #[signal]
    fn focus_changed(intensity: f32);

    #[signal]
    fn lift_completed(success: bool);

    #[signal]
    fn lift_progress(progress: f32);

    #[signal]
    fn lift_visual_height(height: f32);

    #[signal]
    fn camera_trauma(amount: f32);

    #[signal]
    fn hazard_spawned(type_: HazardType);

    #[signal]
    fn hazard_resolved(type_: HazardType);

    #[signal]
    fn day_started(day_index: i32);

    #[func]
    pub fn publish_lift_effort(&mut self, strength: f32) {
        self.base_mut()
            .emit_signal("lift_effort_applied", &[strength.to_variant()]);
    }

    #[func]
    pub fn publish_focus_released(&mut self) {
        self.base_mut().emit_signal("focus_released", &[]);
    }

    #[func]
    pub fn publish_focus_changed(&mut self, intensity: f32) {
        self.base_mut()
            .emit_signal("focus_changed", &[intensity.to_variant()]);
    }

    #[func]
    pub fn publish_lift_completed(&mut self, success: bool) {
        self.base_mut()
            .emit_signal("lift_completed", &[success.to_variant()]);
    }

    #[func]
    pub fn publish_lift_progress(&mut self, progress: f32) {
        self.base_mut()
            .emit_signal("lift_progress", &[progress.to_variant()]);
    }

    #[func]
    pub fn publish_lift_visual_height(&mut self, height: f32) {
        self.base_mut()
            .emit_signal("lift_visual_height", &[height.to_variant()]);
    }

    #[func]
    pub fn publish_camera_trauma(&mut self, amount: f32) {
        self.base_mut()
            .emit_signal("camera_trauma", &[amount.to_variant()]);
    }

    #[func]
    pub fn publish_hazard_spawned(&mut self, type_: HazardType) {
        self.base_mut()
            .emit_signal("hazard_spawned", &[type_.to_variant()]);
    }

    #[func]
    pub fn publish_hazard_resolved(&mut self, type_: HazardType) {
        self.base_mut()
            .emit_signal("hazard_resolved", &[type_.to_variant()]);
    }

    #[func]
    pub fn publish_day_started(&mut self, day_index: i32) {
        self.base_mut()
            .emit_signal("day_started", &[day_index.to_variant()]);
    }
}
