//! This code was AUTOGENERATED using the kinobi library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun kinobi to update it.
//!
//! [https://github.com/metaplex-foundation/kinobi]
//!

use num_derive::FromPrimitive;
use solana_program_error::{ProgramError, ToStr};
use thiserror::Error;

#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
pub enum MplAgentIdentityError {
    /// 0 (0x0) - Invalid System Program
    #[error("Invalid System Program")]
    InvalidSystemProgram,
    /// 1 (0x1) - Invalid instruction data
    #[error("Invalid instruction data")]
    InvalidInstructionData,
    /// 2 (0x2) - Invalid account data
    #[error("Invalid account data")]
    InvalidAccountData,
    /// 3 (0x3) - Invalid MPL Core Program
    #[error("Invalid MPL Core Program")]
    InvalidMplCoreProgram,
    /// 4 (0x4) - Invalid Core Asset
    #[error("Invalid Core Asset")]
    InvalidCoreAsset,
    /// 5 (0x5) - Invalid Agent Token
    #[error("Invalid Agent Token")]
    InvalidAgentToken,
    /// 6 (0x6) - Only the Asset Signer can set the agent token
    #[error("Only the Asset Signer can set the agent token")]
    OnlyAssetSignerCanSetAgentToken,
    /// 7 (0x7) - Agent Token already set
    #[error("Agent Token already set")]
    AgentTokenAlreadySet,
    /// 8 (0x8) - Invalid Agent Identity
    #[error("Invalid Agent Identity")]
    InvalidAgentIdentity,
    /// 9 (0x9) - Agent Identity already registered
    #[error("Agent Identity already registered")]
    AgentIdentityAlreadyRegistered,
}

impl From<MplAgentIdentityError> for ProgramError {
    fn from(e: MplAgentIdentityError) -> Self {
        ProgramError::Custom(e as u32)
    }
}

impl TryFrom<u32> for MplAgentIdentityError {
    type Error = ProgramError;
    fn try_from(error: u32) -> Result<Self, Self::Error> {
        match error {
            0 => Ok(MplAgentIdentityError::InvalidSystemProgram),
            1 => Ok(MplAgentIdentityError::InvalidInstructionData),
            2 => Ok(MplAgentIdentityError::InvalidAccountData),
            3 => Ok(MplAgentIdentityError::InvalidMplCoreProgram),
            4 => Ok(MplAgentIdentityError::InvalidCoreAsset),
            5 => Ok(MplAgentIdentityError::InvalidAgentToken),
            6 => Ok(MplAgentIdentityError::OnlyAssetSignerCanSetAgentToken),
            7 => Ok(MplAgentIdentityError::AgentTokenAlreadySet),
            8 => Ok(MplAgentIdentityError::InvalidAgentIdentity),
            9 => Ok(MplAgentIdentityError::AgentIdentityAlreadyRegistered),
            _ => Err(ProgramError::InvalidArgument),
        }
    }
}

impl ToStr for MplAgentIdentityError {
    fn to_str(&self) -> &'static str {
        match self {
            MplAgentIdentityError::InvalidSystemProgram => "Invalid System Program",
            MplAgentIdentityError::InvalidInstructionData => "Invalid instruction data",
            MplAgentIdentityError::InvalidAccountData => "Invalid account data",
            MplAgentIdentityError::InvalidMplCoreProgram => "Invalid MPL Core Program",
            MplAgentIdentityError::InvalidCoreAsset => "Invalid Core Asset",
            MplAgentIdentityError::InvalidAgentToken => "Invalid Agent Token",
            MplAgentIdentityError::OnlyAssetSignerCanSetAgentToken => {
                "Only the Asset Signer can set the agent token"
            }
            MplAgentIdentityError::AgentTokenAlreadySet => "Agent Token already set",
            MplAgentIdentityError::InvalidAgentIdentity => "Invalid Agent Identity",
            MplAgentIdentityError::AgentIdentityAlreadyRegistered => {
                "Agent Identity already registered"
            }
        }
    }
}
