use crate::lisp::error::LispError;

use std::{error, fmt, io};

use sdl2::ttf;

#[derive(Debug)]
pub enum AppError {
    Lisp(LispError),
    File(io::Error),
    Sdl(String),
    SdlTTF(SdlTTFError),
}

impl fmt::Display for AppError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Lisp(e) => write!(f, "lisp error: {}", e),
            Self::File(e) => write!(f, "file error: {}", e),
            Self::Sdl(e) => write!(f, "sdl2 error: {}", e),
            Self::SdlTTF(e) => write!(f, "ttf error: {}", e),
        }
    }
}

#[derive(Debug)]
pub enum SdlTTFError {
    Font(ttf::FontError),
    Init(ttf::InitError),
}

impl fmt::Display for SdlTTFError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Font(e) => write!(f, "font error: {}", e),
            Self::Init(e) => write!(f, "init error: {}", e),
        }
    }
}

impl error::Error for AppError {}
impl error::Error for SdlTTFError {}