use serde::Serialize;
use std::fmt;

#[derive(Debug, Serialize)]
pub enum SerialError {
    OpenError,
    CloseError,
    ScanError,
    InvalidConfig,
    AlreadyConnected,
    StateError,
    NoRecordedData,
    ExportError,
    ImportError,
}

impl fmt::Display for SerialError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            SerialError::OpenError => write!(f, "Opening Error"),
            SerialError::CloseError => write!(f, "Closing Error"),
            SerialError::ScanError => write!(f, "Scan Error"),
            SerialError::InvalidConfig => write!(f, "Invalid Config"),
            SerialError::AlreadyConnected => write!(f, "Already Connected"),
            SerialError::StateError => write!(f, "State Error"),
            SerialError::NoRecordedData => write!(f, "No Recorded Data"),
            SerialError::ExportError => write!(f, "Export Error"),
            SerialError::ImportError => write!(f, "Import Error"),
        }
    }
}

#[derive(Debug)]
pub enum CodecError {
    InvalidHeader,
    InvalidTail,
    InvalidLength,
    InvalidFrameType,
    PayloadTooLarge,
}

impl fmt::Display for CodecError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            CodecError::InvalidHeader => write!(f, "Invalid Header"),
            CodecError::InvalidTail => write!(f, "Invalid Tail"),
            CodecError::InvalidLength => write!(f, "Invalid Length"),
            CodecError::InvalidFrameType => write!(f, "Invalid Frame Type"),
            CodecError::PayloadTooLarge => write!(f, "Payload too large"),
        }
    }
}

impl std::error::Error for CodecError {}
