use hotaru::Value;
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub enum Server {
Local,
MainAuth(String)
}
impl Server {
pub fn from_string(s: &str) -> Self {
if s == "local" {
Server::Local
} else {
Server::MainAuth(s.to_string())
}
}
pub fn get_host(&self) -> &str {
match self {
Server::Local => "local",
Server::MainAuth(host) => host,
}
}
pub fn is_local(&self) -> bool {
matches!(self, Server::Local)
}
pub fn get_address(&self) -> String {
if self.is_local() {
format!("http://{}", crate::op::APP.binding)
} else {
format!("https://{}", self.get_host())
}
}
}
impl std::fmt::Display for Server {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.get_host().fmt(f)
}
}
impl Into<String> for Server {
fn into(self) -> String {
self.get_host().to_string()
}
}
impl From<&str> for Server {
fn from(s: &str) -> Self {
Server::from_string(s)
}
}
impl From<String> for Server {
fn from(s: String) -> Self {
Server::from_string(&s)
}
}
impl From<Value> for Server {
fn from(value: Value) -> Self {
Self::from_string(&value.string())
}
}
impl Into<Value> for Server {
fn into(self) -> Value {
Value::from(self.get_host())
}
}