use serde::{Deserialize, Serialize};

/// Issue state. Stored as `"open"` or `"closed"`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum IssueState {
    Open,
    Closed,
}

impl std::fmt::Display for IssueState {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            IssueState::Open => write!(f, "open"),
            IssueState::Closed => write!(f, "closed"),
        }
    }
}

impl std::str::FromStr for IssueState {
    type Err = &'static str;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "open" => Ok(IssueState::Open),
            "closed" => Ok(IssueState::Closed),
            _ => Err("unknown issue state"),
        }
    }
}

/// Reaction / emoji type. Stored as `"thumbs_up"`, `"eyes"`, `"heart"`, `"party"`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum ReactionType {
    ThumbsUp,
    Eyes,
    Heart,
    Party,
}

impl std::fmt::Display for ReactionType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ReactionType::ThumbsUp => write!(f, "thumbs_up"),
            ReactionType::Eyes => write!(f, "eyes"),
            ReactionType::Heart => write!(f, "heart"),
            ReactionType::Party => write!(f, "party"),
        }
    }
}

impl std::str::FromStr for ReactionType {
    type Err = &'static str;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "thumbs_up" => Ok(ReactionType::ThumbsUp),
            "eyes" => Ok(ReactionType::Eyes),
            "heart" => Ok(ReactionType::Heart),
            "party" => Ok(ReactionType::Party),
            _ => Err("unknown reaction type"),
        }
    }
}

pub use issue::Entity as Issue;
pub use issue_assignee::Entity as IssueAssignee;
pub use issue_comment::Entity as IssueComment;
pub use issue_comment_reaction::Entity as IssueCommentReaction;
pub use issue_label::Entity as IssueLabel;
pub use issue_pull_request::Entity as IssuePullRequest;
pub use issue_reaction::Entity as IssueReaction;
pub use issue_repo::Entity as IssueRepo;
pub use issue_subscriber::Entity as IssueSubscriber;

pub mod issue;
pub mod issue_assignee;
pub mod issue_comment;
pub mod issue_comment_reaction;
pub mod issue_label;
pub mod issue_pull_request;
pub mod issue_reaction;
pub mod issue_repo;
pub mod issue_subscriber;
