use acir::FieldElement;
use nargo::{NargoError, foreign_calls::transcript::TranscriptError};
use noirc_abi::{
AbiReturnType,
errors::{AbiError, InputParserError},
input_parser::InputValue,
};
use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum FilesystemError {
#[error("Cannot find input file '{0}'")]
MissingInputFile(PathBuf),
#[error("Failed to create output file '{0}': {1}")]
OutputFileCreationFailed(PathBuf, String),
#[error("Failed to parse input file '{0}': {1}")]
InvalidInputFile(PathBuf, String),
#[error("Cannot find bytecode file '{0}'")]
MissingBytecodeFile(PathBuf),
#[error("Failed to read bytecode file '{0}': {1}")]
InvalidBytecodeFile(PathBuf, String),
#[error("Failed to create output witness file '{0}': {1}")]
OutputWitnessCreationFailed(PathBuf, String),
#[error(transparent)]
IoError(#[from] std::io::Error),
}
#[derive(Debug, Error)]
pub enum CliError {
#[error(transparent)]
FilesystemError(#[from] FilesystemError),
#[error("Failed to deserialize inputs")]
InputDeserializationError(#[from] InputParserError),
#[error(transparent)]
TranscriptError(#[from] TranscriptError),
#[error(transparent)]
AbiError(#[from] AbiError),
#[error("Failed to deserialize artifact from JSON")]
ArtifactDeserializationError(#[from] serde_json::Error),
#[error("Failed to deserialize circuit from bytecode")]
CircuitDeserializationError(#[from] std::io::Error),
#[error(transparent)]
CircuitExecutionError(#[from] NargoError<FieldElement>),
#[error("Failed to parse witness value {0}")]
WitnessValueError(String),
#[error("Failed to parse witness index {0}")]
WitnessIndexError(String),
#[error("Failed to serialize output witness: {0}")]
OutputWitnessSerializationFailed(#[from] toml::ser::Error),
#[error("Unexpected return value: expected {expected:?}; got {actual:?}")]
UnexpectedReturn { expected: InputValue, actual: Option<InputValue> },
#[error("Missing return witnesses; expected {expected:?}")]
MissingReturn { expected: AbiReturnType },
#[error("Missing contract function name; options: {names:?}")]
MissingContractFn { names: Vec<String> },
#[error("Unknown contract function '{name}'; options: {names:?}")]
UnknownContractFn { name: String, names: Vec<String> },
}