//! Error handling for TACO format operations

use std::io;
use thiserror::Error;

/// Custom error types for TACO operations
#[derive(Error, Debug)]
pub enum Error {
    #[error("I/O error: {0}")]
    Io(#[from] io::Error),

    #[error("Invalid TACO format: {0}")]
    InvalidFormat(String),

    #[error("Compression error: {0}")]
    Compression(String),

    #[error("Decompression error: {0}")]
    Decompression(String),

    #[error("Invalid metadata: {0}")]
    InvalidMetadata(String),

    #[error("Frame access error: {0}")]
    FrameAccess(String),

    #[error("Invalid frame index: {0}")]
    InvalidFrameIndex(String),

    #[error("Data shape mismatch: {0}")]
    ShapeMismatch(String),

    #[error("Serialization error: {0}")]
    Serialization(String),

    #[error("Deserialization error: {0}")]
    Deserialization(String),

    #[error("Unsupported feature: {0}")]
    UnsupportedFeature(String),

    #[error("Missing data: {0}")]
    MissingData(String),
}

/// Result type for TACO operations
pub type Result<T> = std::result::Result<T, Error>;

impl From<serde_yaml::Error> for Error {
    fn from(err: serde_yaml::Error) -> Self {
        Error::Serialization(err.to_string())
    }
}

impl From<serde_json::Error> for Error {
    fn from(err: serde_json::Error) -> Self {
        Error::Serialization(err.to_string())
    }
}

// impl From<std::io::Error> for Error {
//     fn from(err: std::io::Error) -> Self {
//         Error::Io()
//     }
// }
