use crate::edicts::Edict;
use sdk_raw::interfaces::plugin_helpers::INVALID_QUERY_CVAR_COOKIE;
use sdk_raw::vcall;
use std::ffi::{CStr, c_int};
interface! {
#[doc(alias("IServerPluginHelpers"))]
pub struct PluginHelpers(sys::IServerPluginHelpers) = Engine sdk_raw::interfaces::plugin_helpers::VERSION;
}
#[doc(alias("QueryCvarCookie_t"))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct QueryCvarCookie(pub c_int);
impl<'s> PluginHelpers<'s> {
#[doc(alias("ClientCommand"))]
pub fn client_command(self, client: Edict<'_>, command: &CStr) {
unsafe {
vcall!(self.as_ptr() => IServerPluginHelpers_ClientCommand(client.as_ptr(), command.as_ptr()))
};
}
#[doc(alias("StartQueryCvarValue"))]
pub fn start_query_cvar_value(self, client: Edict<'_>, name: &CStr) -> Option<QueryCvarCookie> {
let cookie = unsafe {
vcall!(self.as_ptr() => IServerPluginHelpers_StartQueryCvarValue(client.as_ptr(), name.as_ptr()))
};
(cookie != INVALID_QUERY_CVAR_COOKIE).then_some(QueryCvarCookie(cookie))
}
}