use thiserror::Error;

pub type PsdkFatherResult<T> = Result<T, PsdkFatherError>;
pub type PsdkLockDeviceResult<T> = Result<T, PsdkLockError>;

#[derive(Error, Debug)]
pub enum PsdkLockError {
  #[error("LockDevice: {0}")]
  LockDevice(String),
  #[error("LockDevice: {0}")]
  LockArgContext(String),
  #[error("WriteOptions: {0}")]
  WriteOptions(String),
}

#[derive(Error, Debug)]
pub enum PsdkFatherError {
  #[error(transparent)]
  Io(#[from] std::io::Error),
  #[error("Encoding: {0}")]
  Encoding(String),
  #[error(transparent)]
  Lock(#[from] PsdkLockError),
  #[error("Custom: {0}")]
  Custom(String),
  #[error("[imagep] {0}")]
  Image(String),
}

impl From<base64::DecodeError> for PsdkFatherError {
  fn from(value: base64::DecodeError) -> Self {
    Self::Custom(format!("wrong base64 data to decode: {:?}", value))
  }
}
