use std::io;

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("{0}")]
    Io(#[from] io::Error),
    #[error("Unhandled marker byte: {0:#02x}")]
    InvalidMarker(u8),
    #[error("Malformed JPEG/JFIF header")]
    MalformedHeader,
    #[error("Multiple SOF markers within one image")]
    MultipleSofMarkers,
    #[error("Duplicate quantization table [{0}]")]
    DuplicateQt(usize),
    #[error("Invalid quantization table index [{0}]")]
    InvalidQtIndex(usize),
    #[error("Duplicate component [{0}]")]
    DuplicateComponent(usize),
    #[error("Invalid component index [{0}]")]
    InvalidComponentIndex(usize),
    #[error("Malformed Huffman bit sequence: {0:016b}")]
    MalformedHuffmanCode(u16),
    #[error("Invalid huffman table")]
    InvalidHuffmanTable,
    #[error("Invalid quantization table precision: {0}-byte")]
    InvalidQtPrecision(usize),

    #[error("Missing DC Huffman table [{0}]")]
    MissingDCHT(u8),
    #[error("Missing AC Huffman table [{0}]")]
    MissingACHT(u8),
    #[error("Missing quantization table [{0}]")]
    MissingQT(usize),

    // Unimplemented features
    #[error("Unsupported sample precision: {0} bits/sample")]
    UnimplementedSamplePrecision(u8),
    #[error("Unsupported {0} sampling factor: {1}x{2}")]
    UnimplementedSamplingFactor(&'static str, u8, u8),
    #[error("Unsupported component count: {0}")]
    UnimplementedComponentCount(u8),
    #[error("{0} is not supported")]
    UnimplementedFeature(&'static str),
}
