use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use solana_program::{
decode_error::DecodeError,
msg,
program_error::{PrintProgramError, ProgramError},
};
use thiserror::Error;
#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
pub enum NFTPacksError {
#[error("Allowed amount to redeem should be more then 0")]
WrongAllowedAmountToRedeem,
#[error("Wrong redeem date")]
WrongRedeemDate,
#[error("Card probability is missing")]
CardProbabilityMissing,
#[error("Wrong card probability value")]
WrongCardProbability,
#[error("Cards for this pack shouldn't have probability value")]
CardShouldntHaveProbabilityValue,
#[error("Proved vouchers mismatch pack vouchers")]
ProvedVouchersMismatchPackVouchers,
#[error("Pack is already ended")]
PackIsAlreadyEnded,
#[error("NFT pack set not fully configured")]
PackSetNotConfigured,
#[error("Can't activate NFT pack in current state")]
CantActivatePack,
#[error("Pack set should be activated")]
PackSetNotActivated,
#[error("Proving process for this pack is completed")]
ProvingPackProcessCompleted,
#[error("Proving process for this voucher is completed")]
ProvingVoucherProcessCompleted,
#[error("Received edition from wrong master")]
WrongEdition,
#[error("Received wrong edition mint")]
WrongEditionMint,
#[error("Overflow")]
Overflow,
#[error("Underflow")]
Underflow,
#[error("Pack set should be empty to delete it")]
NotEmptyPackSet,
#[error("Wrong pack state to change data")]
WrongPackState,
#[error("Pack set is immutable")]
ImmutablePackSet,
#[error("Can't set the same value")]
CantSetTheSameValue,
#[error("Wrong max supply value")]
WrongMaxSupply,
#[error("Voucher should have supply greater then 0")]
WrongVoucherSupply,
#[error("Card ran out of editions")]
CardDoesntHaveEditions,
#[error("User redeemed all allowed cards")]
UserRedeemedAllCards,
#[error("URI too long")]
UriTooLong,
#[error("Card doesn't have max supply")]
CardDoesntHaveMaxSupply,
#[error("Master edition should have unlimited supply")]
WrongMasterSupply,
#[error("Pack set doesn't have total editions")]
MissingEditionsInPack,
#[error("User already got next card to redeem")]
AlreadySetNextCardToRedeem,
#[error("Can't close the pack before end date")]
EndDateNotArrived,
#[error("Pack description too long")]
DescriptionTooLong,
#[error("Whitelisted creator inactive")]
WhitelistedCreatorInactive,
#[error("Wrong whitelisted creator address")]
WrongWhitelistedCreator,
#[error("Voucher owner mismatch")]
WrongVoucherOwner,
#[error("Cards for this pack shouldn't have supply value")]
CardShouldntHaveSupplyValue,
#[error("Pack is already full of cards")]
PackIsFullWithCards,
#[error("Card weights should be cleaned up")]
WeightsNotCleanedUp,
#[error("User already redeemed this card")]
CardAlreadyRedeemed,
#[error("User can't redeem this card")]
UserCantRedeemThisCard,
#[error("Invalid weight position")]
InvalidWeightPosition,
}
impl From<NFTPacksError> for ProgramError {
fn from(e: NFTPacksError) -> Self {
ProgramError::Custom(e as u32)
}
}
impl<T> DecodeError<T> for NFTPacksError {
fn type_of() -> &'static str {
"NFTPacksError"
}
}
impl PrintProgramError for NFTPacksError {
fn print<E>(&self)
where
E: 'static + std::error::Error + DecodeError<E> + PrintProgramError + FromPrimitive,
{
msg!(&self.to_string())
}
}