use crate::prelude::*;
use std::cmp::Ordering;
use std::convert::Infallible;
use std::time::Duration;
pub const RED_URL: &str = "https://redacted.sh";
pub const RED_URL_CH: &str = "https://redacted.ch";
pub const OPS_URL: &str = "https://orpheus.network";
pub const RED_TRACKER_URL: &str = "https://flacsfor.me";
pub const OPS_TRACKER_URL: &str = "https://home.opsfet.ch";
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(from = "String", into = "String")]
pub enum Indexer {
#[default]
Red,
Pth,
Ops,
Other(String),
}
impl Indexer {
#[must_use]
pub fn as_lowercase(&self) -> &str {
match self {
Indexer::Red => "red",
Indexer::Pth => "pth",
Indexer::Ops => "ops",
Indexer::Other(value) => value,
}
}
#[must_use]
pub fn to_uppercase(&self) -> String {
self.as_lowercase().to_uppercase()
}
#[must_use]
pub fn gazelle_rate_limit(&self) -> (usize, Duration) {
match self {
Indexer::Red => (8, Duration::from_secs(10)),
Indexer::Ops => (4, Duration::from_secs(10)),
_ => (5, Duration::from_secs(10)),
}
}
#[must_use]
pub fn gazelle_retry_delays(&self) -> Vec<Duration> {
match self {
Indexer::Ops => vec![Duration::from_secs(10), Duration::from_secs(20)],
_ => vec![Duration::from_secs(5), Duration::from_secs(10)],
}
}
pub fn match_with_alts(&self, other: &Indexer) -> bool {
self == other || (self == &Indexer::Red && other == &Indexer::Pth)
}
}
impl From<&str> for Indexer {
fn from(value: &str) -> Self {
let lowercase = value.to_lowercase();
match lowercase.as_str() {
"red" => Indexer::Red,
"pth" => Indexer::Pth,
"ops" => Indexer::Ops,
_ => Indexer::Other(lowercase),
}
}
}
impl From<String> for Indexer {
fn from(value: String) -> Self {
Indexer::from(value.as_str())
}
}
impl From<Indexer> for String {
fn from(value: Indexer) -> Self {
value.as_lowercase().to_owned()
}
}
impl FromStr for Indexer {
type Err = Infallible;
fn from_str(value: &str) -> Result<Self, Self::Err> {
Ok(Indexer::from(value))
}
}
impl Ord for Indexer {
fn cmp(&self, other: &Self) -> Ordering {
self.as_lowercase().cmp(other.as_lowercase())
}
}
impl PartialOrd for Indexer {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Display for Indexer {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
Display::fmt(&self.to_uppercase(), f)
}
}