use std::path::PathBuf;
use ogg::reading::OggReadError;
use tempfile::PersistError;
use thiserror::Error;
use crate::{escaping, Codec};
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error("Unable to open file `{0}` due to `{1}`")]
FileOpenError(PathBuf, std::io::Error),
#[error("Unable to read from file `{0}` due to `{1}`")]
FileReadError(PathBuf, std::io::Error),
#[error("Unable to write to file `{0}` due to `{1}`")]
FileWriteError(PathBuf, std::io::Error),
#[error("Unable to copy `{0}` to `{1}` due to `{2}`")]
FileCopy(PathBuf, PathBuf, std::io::Error),
#[error("Unable to open temporary file in `{0}` due to `{1}`")]
TempFileOpenError(PathBuf, std::io::Error),
#[error("Ogg decoding error: `{0}`")]
OggDecode(OggReadError),
#[error("Error reading from file: `{0}`")]
ReadError(std::io::Error),
#[error("Error writing to file: `{0}`")]
WriteError(std::io::Error),
#[error("Not a stream of type {0}")]
MissingStream(Codec),
#[error("Unknown codec")]
UnknownCodec,
#[error("Malformed identification header")]
MalformedIdentificationHeader,
#[error("Malformed comment header")]
MalformedCommentHeader,
#[error("Missing separator in comment")]
MissingCommentSeparator,
#[error("UTF-8 encoding error")]
UTF8Error(#[from] std::string::FromUtf8Error),
#[error("R128 tag has invalid value: `{0}`")]
InvalidR128Tag(String),
#[error("A computed gain value was not representable")]
GainOutOfBounds,
#[error("Failed to delete `{0}` due to `{1}`")]
FileDelete(PathBuf, std::io::Error),
#[error("Failed to persist temporary file due to `{0}`")]
PersistError(#[from] PersistError),
#[error("Unsupported channel count: `{0}`")]
InvalidChannelCount(usize),
#[error("Opus error: `{0}`")]
OpusError(opus::Error),
#[error("Console IO error: `{0}`")]
ConsoleIoError(std::io::Error),
#[error("An invalid number of threads was specified")]
InvalidThreadCount,
#[error("The parent folder of `{0}` could not be found")]
NoParentError(PathBuf),
#[error("The path `{0}` did not have a final named component")]
NotAFilePath(PathBuf),
#[error("Invalid Opus comment field name: `{0}`")]
InvalidOpusCommentFieldName(String),
#[error("{0}")]
EscapeDecodeError(#[from] escaping::EscapeDecodeError),
#[error("The operation was interrupted")]
Interrupted,
#[error("Version {1} of codec {0} is not supported")]
UnsupportedCodecVersion(Codec, u64),
#[error("The codec {0} was not supported for this operation")]
UnsupportedCodec(Codec),
#[error("A value could not be represented in a comment header")]
UnrepresentableValueInCommentHeader,
#[error("Unexpected logical stream in Ogg file, serial {0:#x}")]
UnexpectedLogicalStream(u32),
#[error("Channel count and/or sample rate changed between concatenated audio streams")]
UnexpectedAudioParametersChange,
}