api/dto/card.rs
1use serde::{Deserialize, Serialize};
2
3/// A string identifier for a card.
4///
5/// Examples include `"AS"` for Ace of Spades or `"QD"` for Queen of Diamonds.
6pub type CardIdDTO = String;
7
8/// A DTO representing a Card. The value is the "cid" (Card identifier), e.g. "AS", "QD".
9#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
10pub enum CardDTO {
11 /// The card is visible; contains the card identifier (`cid`), e.g., `"AS"`.
12 FaceUp {
13 /// The card id as a two character string format.
14 cid: CardIdDTO,
15 },
16
17 /// The card is hidden and its identity is unknown.
18 FaceDown,
19}
20
21#[cfg(feature = "server")]
22mod server_only {
23 use server::domain::Card;
24
25 use super::*;
26
27 impl CardDTO {
28 /// Constructs a face-up DTO from a domain `Card`.
29 pub fn face_up(card: &Card) -> Self {
30 Self::FaceUp {
31 cid: CardIdDTO::from(card.cid()),
32 }
33 }
34
35 /// Constructs a face-down DTO from a domain `Card`.
36 /// The card itself isn't required during the construction.
37 pub fn face_down(_card: &Card) -> Self {
38 Self::FaceDown
39 }
40 }
41}