use std::ops::Deref;
use mlua::{AsChunk, Chunk, FromLua, Lua, ObjectLike, Result, Table, Value};
use crate::{EventSub, Proxy};
#[derive(Clone)]
pub struct Server(Table);
impl Server {
#[inline]
pub fn get_name(&self) -> Result<String> {
self.0.call_method("get_name", ())
}
#[inline]
pub fn get_puid(&self) -> Result<String> {
self.0.call_method("get_puid", ())
}
#[inline]
pub fn get_rid(&self) -> Result<u64> {
self.0.call_method("get_rid", ())
}
#[inline]
pub fn is_draining(&self) -> Result<bool> {
self.0.call_method("is_draining", ())
}
#[inline]
pub fn is_backup(&self) -> Result<bool> {
self.0.call_method("is_backup", ())
}
#[inline]
pub fn is_dynamic(&self) -> Result<bool> {
self.0.call_method("is_dynamic", ())
}
pub fn get_cur_sess(&self) -> Result<u64> {
self.0.call_method("get_cur_sess", ())
}
#[inline]
pub fn get_pend_conn(&self) -> Result<u64> {
self.0.call_method("get_pend_conn", ())
}
#[inline]
pub fn set_maxconn(&self, maxconn: u64) -> Result<()> {
self.0.call_method("set_maxconn", maxconn)
}
#[inline]
pub fn get_maxconn(&self) -> Result<u64> {
self.0.call_method("get_maxconn", ())
}
#[inline]
pub fn set_weight(&self, weight: &str) -> Result<()> {
self.0.call_method("set_weight", weight)
}
#[inline]
pub fn get_weight(&self) -> Result<u32> {
self.0.call_method("get_weight", ())
}
#[inline]
pub fn set_addr(&self, addr: String, port: Option<u16>) -> Result<()> {
self.0.call_method("set_addr", (addr, port))
}
#[inline]
pub fn get_addr(&self) -> Result<String> {
self.0.call_method("get_addr", ())
}
#[inline]
pub fn get_stats(&self) -> Result<Table> {
self.0.call_method("get_stats", ())
}
pub fn get_proxy(&self) -> Result<Proxy> {
self.0.call_method("get_proxy", ())
}
#[inline]
pub fn shut_sess(&self) -> Result<()> {
self.0.call_method("shut_sess", ())
}
#[inline]
pub fn set_drain(&self) -> Result<()> {
self.0.call_method("set_drain", ())
}
#[inline]
pub fn set_maint(&self) -> Result<()> {
self.0.call_method("set_maint", ())
}
#[inline]
pub fn set_ready(&self) -> Result<()> {
self.0.call_method("set_ready", ())
}
#[inline]
pub fn check_enable(&self) -> Result<()> {
self.0.call_method("check_enable", ())
}
#[inline]
pub fn check_disable(&self) -> Result<()> {
self.0.call_method("check_disable", ())
}
#[inline]
pub fn check_force_up(&self) -> Result<()> {
self.0.call_method("check_force_up", ())
}
#[inline]
pub fn check_force_nolb(&self) -> Result<()> {
self.0.call_method("check_force_nolb", ())
}
#[inline]
pub fn check_force_down(&self) -> Result<()> {
self.0.call_method("check_force_down", ())
}
#[inline]
pub fn agent_enable(&self) -> Result<()> {
self.0.call_method("agent_enable", ())
}
#[inline]
pub fn agent_disable(&self) -> Result<()> {
self.0.call_method("agent_disable", ())
}
#[inline]
pub fn agent_force_up(&self) -> Result<()> {
self.0.call_method("agent_force_up", ())
}
#[inline]
pub fn agent_force_down(&self) -> Result<()> {
self.0.call_method("agent_force_down", ())
}
#[inline]
pub fn tracking(&self) -> Result<Option<Server>> {
self.0.call_method("tracking(", ())
}
#[inline]
pub fn get_trackers(&self) -> Result<Vec<Server>> {
self.0.call_method("get_trackers", ())
}
pub fn event_sub(&self, event_types: &[&str], code: impl AsChunk) -> Result<EventSub> {
self.0
.call_function("event_sub", (event_types, Chunk::wrap(code)))
}
}
impl FromLua for Server {
#[inline]
fn from_lua(value: Value, lua: &Lua) -> Result<Self> {
let class = Table::from_lua(value, lua)?;
Ok(Server(class))
}
}
impl Deref for Server {
type Target = Table;
#[inline]
fn deref(&self) -> &Self::Target {
&self.0
}
}