use bevy::{
    diagnostic::FrameTimeDiagnosticsPlugin,
    ecs::reflect::ReflectResource,
    prelude::{App, IntoSystemConfigs, Plugin, Resource, Startup, Update},
    reflect::Reflect,
};
use bevy_rapier3d::prelude::{NoUserData, RapierPhysicsPlugin};

mod components;
mod systems;

pub use components::*;
use systems::*;

#[derive(Resource, Default, Debug, Reflect)]
#[reflect(Resource)]
struct CyberLean {
    pub lean: f32,
}

pub struct CyberActionPlugin;
impl Plugin for CyberActionPlugin {
    fn build(&self, app: &mut App) {
        app.init_resource::<MovementSettings>()
            .register_type::<MovementSettings>()
            .init_resource::<CatControllerSettings>()
            .init_resource::<ActionDebugInstant>()
            .init_resource::<CyberLean>()
            .register_type::<CyberLean>()
            .register_type::<CatControllerSettings>()
            .add_plugins(RapierPhysicsPlugin::<NoUserData>::default())
            .add_systems(Startup, physics_init)
            .add_plugins(FrameTimeDiagnosticsPlugin)
            .add_systems(
                Update,
                (
                    reset_external_forces,
                    cyber_lean,
                    falling_cat,
                    wheel_forces,
                    drag,
                )
                    .chain(),
            );
    }
}
