use serde::{Deserialize, Serialize};
use uuid::Uuid;

/// A user's private taste signal on a manga. Stored as text in
/// `manga_reactions.reaction` (CHECK-constrained), so we map to/from a
/// `&str` at the repo layer rather than deriving a Postgres enum type.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Reaction {
    Like,
    Dislike,
}

impl Reaction {
    pub fn as_str(self) -> &'static str {
        match self {
            Reaction::Like => "like",
            Reaction::Dislike => "dislike",
        }
    }

    /// Parse a stored/inbound value. Returns `None` for anything outside the
    /// closed vocabulary (the DB CHECK guarantees stored rows are valid; this
    /// also guards the inbound API body).
    pub fn parse(s: &str) -> Option<Reaction> {
        match s {
            "like" => Some(Reaction::Like),
            "dislike" => Some(Reaction::Dislike),
            _ => None,
        }
    }
}

/// Response shape for `GET /me/reactions/:manga_id` — the current user's
/// reaction on one manga, or `null` when they haven't reacted.
#[derive(Debug, Clone, Serialize)]
pub struct MangaReaction {
    pub manga_id: Uuid,
    pub reaction: Option<Reaction>,
}
