use std::{ffi::CString, fmt::Debug};

pub mod result;

#[derive(Default)]
#[repr(C)]
pub struct ResourceHandlers {
  pub on_tick: Option<Box<dyn Fn() + 'static>>,
  pub on_sdk_event: Option<Box<dyn Fn(altv_sdk::EventType, altv_sdk::CEventPtr) + 'static>>,
  pub on_base_object_create:
    Option<Box<dyn Fn(altv_sdk::BaseObjectMutPtr, altv_sdk::BaseObjectType) + 'static>>,
  pub on_base_object_destroy:
    Option<Box<dyn Fn(altv_sdk::BaseObjectMutPtr, altv_sdk::BaseObjectType) + 'static>>,
}

impl Debug for ResourceHandlers {
  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    write!(f, "ResourceHandlers {{todo}}")
  }
}

pub type CStringResourceName = CString;
pub type StringResourceName = String;
type ToggleEventTypeFn = fn(CStringResourceName, altv_sdk::EventType, bool);

pub struct ModuleHandlers {
  pub toggle_event_type: ToggleEventTypeFn,
}

// this shit is here for derive(Default) of core_resource Resource
impl Default for ModuleHandlers {
  fn default() -> Self {
    fn placeholder(_: CStringResourceName, _: altv_sdk::EventType, _: bool) {}
    Self {
      toggle_event_type: placeholder,
    }
  }
}

impl ModuleHandlers {
  pub fn new(toggle_event_type: ToggleEventTypeFn) -> Self {
    Self { toggle_event_type }
  }
}

impl Debug for ModuleHandlers {
  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    write!(f, "ResourceHandlers {{todo}}")
  }
}

#[repr(C)]
pub struct CBool {
  pub value: bool,
}
