use bevy::prelude::*;
use bevy_kira_audio::prelude::*;
use std::path::Path;

use crate::core::game_state::{GameStartupSet, GameState};

fn restart_audio(asset_server: Res<AssetServer>, audio: Res<Audio>, background: Res<AudioChannel<Background>>) {
    audio.stop();
    background.stop();
    background.play(asset_server.load("sounds/king_dede_theme.ogg")).looped();
}

#[derive(Resource)]
pub struct Background;

#[derive(Resource)]
pub struct Suction;

#[derive(Resource)]
pub struct Poyoo;

pub struct MySoundPlugin;

impl Plugin for MySoundPlugin {
    fn build(&self, app: &mut App) {
        app.add_plugins(AudioPlugin)
            .add_audio_channel::<Background>()
            .add_audio_channel::<Suction>()
            .add_audio_channel::<Poyoo>()
            .add_systems(OnEnter(GameState::Starting), restart_audio.in_set(GameStartupSet));
    }
}
