1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::CardCost;

pub use companion::CompanionCard;
mod companion;

pub use location::LocationCard;
mod location;

pub use item::ItemCard;
mod item;

use super::Price;

#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)]
pub enum SupportCard {
    Companion(CompanionCard),
    Location(LocationCard),
    Item(ItemCard),
}

impl SupportCard {
    pub fn name(&self) -> &'static str {
        match self {
            Self::Companion(card) => card.name(),
            Self::Location(card)  => card.name(),
            Self::Item(card)      => card.name(),
        }
    }

    /// Returns `Some(price)` in Lucky Coins to buy the given card in the shop.
    /// 
    /// Cards not sold in the shop (such as [`Paimon`]) return `None`
    /// 
    /// [`Paimon`]: CompanionCard::Paimon
    pub fn shop_price(&self) -> Option<Price> {
        match self {
            Self::Companion(card) => card.shop_price(),
            Self::Location(card)  => Some(card.shop_price()),
            Self::Item(card)      => Some(card.shop_price()),
        }
    }

    pub fn cost(&self) -> CardCost {
        match self {
            Self::Companion(card) => card.cost(),
            Self::Location(card)  => card.cost(),
            Self::Item(card)      => card.cost(),
        }
    }
}

use std::cmp::Ordering;
use super::CardOrd;
impl CardOrd for SupportCard {
    fn cmp(&self, other: &Self) -> Ordering {
        // Location < Companion < Item
        match (self, other) {
            (Self::Location(x), Self::Location(y))   => x.cmp(y),
            (Self::Companion(x), Self::Companion(y)) => x.cmp(y),
            (Self::Item(x), Self::Item(y))           => x.cmp(y),
            (Self::Location(_), _)  => Ordering::Less,
            (_, Self::Location(_))  => Ordering::Greater,
            (Self::Companion(_), _) => Ordering::Less,
            (_, Self::Companion(_)) => Ordering::Greater,
        }
    }
}