use std::{fmt::Debug, io, path::StripPrefixError};

pub enum Error {
    Unspecified(ErrorKind),
    Public(ErrorKind),
    Templates(ErrorKind),
}

impl Debug for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Error::Unspecified(e) => e.fmt(f),
            Error::Public(e) => {
                writeln!(f, "failed to compile file in 'public/': {:?}", e)
            }
            Error::Templates(e) => {
                writeln!(f, "failed to compile file in 'templates/': {:?}", e)
            }
        }
    }
}

pub enum ErrorKind {
    ReadFile(io::Error),
    WriteFile(io::Error),
    CopyFile(io::Error),

    ReadDir(io::Error),
    CreateDir(io::Error),
    RemoveDir(io::Error),

    StripPrefix(StripPrefixError),
    PathManip,
}

impl Debug for ErrorKind {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ErrorKind::ReadFile(e) => writeln!(f, "failed to read file: {}", e),
            ErrorKind::WriteFile(e) => writeln!(f, "failed to write file: {}", e),
            ErrorKind::CopyFile(e) => writeln!(f, "failed to copy file: {}", e),

            ErrorKind::ReadDir(e) => writeln!(f, "failed to read directory: {}", e),
            ErrorKind::CreateDir(e) => writeln!(f, "failed to create directory: {}", e),
            ErrorKind::RemoveDir(e) => writeln!(f, "failed to remove directory: {}", e),

            ErrorKind::StripPrefix(e) => {
                writeln!(f, "error during string manipulation: {}", e)
            }
            ErrorKind::PathManip => writeln!(
                f,
                "error during path manipulation (path might contain unsupported special characters)"
            ),
        }
    }
}
