// File: src/error.rs
// Author: Hadi Cahyadi <cumulus13@gmail.com>

use std::fmt;

#[derive(Debug)]
pub enum MixerError {
    ComInit(String),
    DeviceNotFound(String),
    AudioApi(String),
    Io(std::io::Error),
}

impl fmt::Display for MixerError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            MixerError::ComInit(msg) => write!(f, "COM initialization failed: {msg}"),
            MixerError::DeviceNotFound(msg) => write!(f, "Audio device not found: {msg}"),
            MixerError::AudioApi(msg) => write!(f, "Windows Audio API error: {msg}"),
            MixerError::Io(e) => write!(f, "I/O error: {e}"),
        }
    }
}

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

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