use crate::consts::colors::*;

use sdl2::pixels::Color;

#[derive(Debug)]
pub struct Message {
    pub text: String,
    pub kind: MessageKind,
}

impl Message {
    pub fn new() -> Self {
        Self {
            text: String::new(),
            kind: MessageKind::Info,
        }
    }

    pub fn kind(mut self, kind: MessageKind) -> Self {
        self.kind = kind;
        self
    }

    pub fn text<S: AsRef<str>>(mut self, text: S) -> Self {
        self.text = text.as_ref().into();
        self
    }

    pub fn set_info<S: AsRef<str>>(&mut self, text: S) {
        self.text = text.as_ref().into();
        self.kind = MessageKind::Info;
    }

    pub fn set_error<S: AsRef<str>>(&mut self, text: S) {
        self.text = text.as_ref().into();
        self.kind = MessageKind::Error;
    }

    pub fn set_hint<S: AsRef<str>>(&mut self, text: S) {
        self.text = text.as_ref().into();
        self.kind = MessageKind::Hint;
    }

    pub fn clear(&mut self) {
        self.text.clear();
        self.kind = MessageKind::Info;
    }
}

#[derive(Debug, Copy, Clone)]
pub enum MessageKind {
    Error,
    Info,
    Hint,
    LispResult,
}

impl<T> From<T> for Message
where
    T: AsRef<str>,
{
    fn from(item: T) -> Self {
        return Message {
            text: item.as_ref().into(),
            kind: MessageKind::Info,
        };
    }
}

impl Into<Color> for MessageKind {
    fn into(self) -> Color {
        match self {
            Self::Error => PINK,
            Self::Info => WHITE,
            Self::Hint => CYAN,
            Self::LispResult => GREY,
        }
    }
}