use std::fmt;
use crate::search::param::Param;
use crate::search::query::Query;
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[allow(missing_docs)]
pub enum Criterion {
Card(CardIs),
Printing(PrintingIs),
}
impl fmt::Display for Criterion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Criterion::Card(inner) => fmt::Display::fmt(inner, f),
Criterion::Printing(inner) => fmt::Display::fmt(inner, f),
}
}
}
impl From<Criterion> for Query {
fn from(criterion: Criterion) -> Self {
Query::Param(Param::criterion(criterion))
}
}
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[cfg_attr(test, derive(strum::EnumIter))]
pub enum CardIs {
ColorIndicator,
EvenCmc,
OddCmc,
Phyrexian,
Hybrid,
Split,
Flip,
Transform,
ModalDfc,
Meld,
Leveler,
Spell,
Permanent,
Historic,
Party,
Modal,
Vanilla,
FrenchVanilla,
Funny,
Commander,
Brawler,
Companion,
Reserved,
Adventure,
BicycleLand,
#[doc(alias = "triome")]
TricycleLand,
BounceLand,
CanopyLand,
CheckLand,
DualLand,
FastLand,
FetchLand,
FilterLand,
GainLand,
PainLand,
ScryLand,
ShadowLand,
ShockLand,
StorageLand,
#[doc(alias = "manland")]
CreatureLand,
TriLand,
#[doc(alias = "tango")]
BattleLand,
}
impl fmt::Display for CardIs {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}:{}",
match self {
CardIs::ColorIndicator => "has", CardIs::EvenCmc | CardIs::OddCmc => "cmc",
_ => "is",
},
match self {
CardIs::ColorIndicator => "indicator",
CardIs::EvenCmc => "even",
CardIs::OddCmc => "odd",
CardIs::Phyrexian => "phyrexian",
CardIs::Hybrid => "hybrid",
CardIs::Split => "split",
CardIs::Flip => "flip",
CardIs::Transform => "transform",
CardIs::ModalDfc => "modal_dfc",
CardIs::Meld => "meld",
CardIs::Leveler => "leveler",
CardIs::Spell => "spell",
CardIs::Permanent => "permanent",
CardIs::Historic => "historic",
CardIs::Party => "party",
CardIs::Modal => "modal",
CardIs::Vanilla => "vanilla",
CardIs::FrenchVanilla => "french_vanilla",
CardIs::Funny => "funny",
CardIs::Commander => "commander",
CardIs::Brawler => "brawler",
CardIs::Companion => "companion",
CardIs::Reserved => "reserved",
CardIs::Adventure => "adventure",
CardIs::BicycleLand => "bicycle_land",
CardIs::TricycleLand => "tricycle_land",
CardIs::BounceLand => "bounce_land",
CardIs::CanopyLand => "canopy_land",
CardIs::CheckLand => "check_land",
CardIs::DualLand => "dual",
CardIs::FastLand => "fast_land",
CardIs::FetchLand => "fetch_land",
CardIs::FilterLand => "filter_land",
CardIs::GainLand => "gain_land",
CardIs::PainLand => "pain_land",
CardIs::ScryLand => "scry_land",
CardIs::ShadowLand => "shadow_land",
CardIs::ShockLand => "shock_land",
CardIs::StorageLand => "storage_land",
CardIs::CreatureLand => "creature_land",
CardIs::TriLand => "tri_land",
CardIs::BattleLand => "battle_land",
}
)
}
}
impl From<CardIs> for Query {
fn from(card: CardIs) -> Self {
Criterion::Card(card).into()
}
}
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
#[cfg_attr(test, derive(strum::EnumIter))]
pub enum PrintingIs {
NewCard,
NewRarity,
NewArt,
NewArtist,
NewFlavor,
NewFrame,
NewLanguage,
Watermark,
Full,
Nonfoil,
Foil,
HiRes,
Digital,
Promo,
Spotlight,
Masterpiece,
Unique,
FirstPrint,
Reprint,
}
impl fmt::Display for PrintingIs {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}:{}",
match self {
PrintingIs::NewCard
| PrintingIs::NewRarity
| PrintingIs::NewArt
| PrintingIs::NewArtist
| PrintingIs::NewFlavor
| PrintingIs::NewFrame
| PrintingIs::NewLanguage => "new",
PrintingIs::Watermark => "has", _ => "is",
},
match self {
PrintingIs::NewCard => "card",
PrintingIs::NewRarity => "rarity",
PrintingIs::NewArt => "art",
PrintingIs::NewArtist => "artist",
PrintingIs::NewFlavor => "flavor",
PrintingIs::NewFrame => "frame",
PrintingIs::NewLanguage => "language",
PrintingIs::Watermark => "watermark",
PrintingIs::Full => "full",
PrintingIs::Foil => "foil",
PrintingIs::Nonfoil => "nonfoil",
PrintingIs::HiRes => "hires",
PrintingIs::Digital => "digital",
PrintingIs::Promo => "promo",
PrintingIs::Spotlight => "spotlight",
PrintingIs::FirstPrint => "first_print",
PrintingIs::Reprint => "reprint",
PrintingIs::Masterpiece => "masterpiece",
PrintingIs::Unique => "unique",
}
)
}
}
impl From<PrintingIs> for Query {
fn from(printing: PrintingIs) -> Self {
Criterion::Printing(printing).into()
}
}
#[cfg(test)]
mod tests {
use strum::IntoEnumIterator;
use super::*;
use crate::search::Search;
#[tokio::test]
#[ignore]
async fn all_card_is() {
for criterion in CardIs::iter() {
Query::from(criterion)
.random()
.await
.unwrap_or_else(|_| panic!("Failed to get a card for {}", criterion));
}
}
#[tokio::test]
#[ignore]
async fn all_printing_is() {
for criterion in PrintingIs::iter() {
Query::from(criterion)
.random()
.await
.unwrap_or_else(|_| panic!("Failed to get a printing for {}", criterion));
}
}
}