use thiserror::Error;
#[cfg(feature = "native")]
use solana_client::client_error::ClientError;
#[derive(Debug, Error)]
pub enum SdkError {
#[cfg(feature = "native")]
#[error("RPC error: {0}")]
Rpc(#[from] ClientError),
#[error("Invalid account discriminator: expected {expected}, got {actual}")]
InvalidDiscriminator { expected: String, actual: String },
#[error("Account not found: {0}")]
AccountNotFound(String),
#[error("Invalid data length: expected {expected}, got {actual}")]
InvalidDataLength { expected: usize, actual: usize },
#[error("Invalid outcome count: {count} (must be {min}-{max})", min = crate::program::constants::MIN_OUTCOMES, max = crate::program::constants::MAX_OUTCOMES)]
InvalidOutcomeCount { count: u8 },
#[error("Invalid outcome index: {index} (max {max})")]
InvalidOutcomeIndex { index: u8, max: u8 },
#[error("Invalid payout numerators")]
InvalidPayoutNumerators,
#[error("Payout vector exceeds u32 bounds")]
PayoutVectorExceedsU32,
#[error("Invalid scalar range")]
InvalidScalarRange,
#[error("Scalar outcome indexes must be distinct")]
DuplicateScalarOutcomes,
#[error("Too many makers: {count} (max {max})", max = crate::program::constants::MAX_MAKERS)]
TooManyMakers { count: usize },
#[error("Signature verification failed")]
SignatureVerificationFailed,
#[error("Invalid signature")]
InvalidSignature,
#[error("Serialization error: {0}")]
Serialization(String),
#[error("Invalid side value: {0} (must be 0 or 1)")]
InvalidSide(u8),
#[error("Invalid market status: {0}")]
InvalidMarketStatus(u8),
#[error("Missing required field: {0}")]
MissingField(String),
#[error("Arithmetic overflow")]
Overflow,
#[error("Invalid mint order")]
InvalidMintOrder,
#[error("Orderbook already exists")]
OrderbookExists,
#[error("Invalid market")]
InvalidMarket,
#[error("Market already settled")]
MarketSettled,
#[error("Invalid program ID")]
InvalidProgramId,
#[error("Invalid orderbook")]
InvalidOrderbook,
#[error("Full fill required")]
FullFillRequired,
#[error("Division by zero")]
DivisionByZero,
#[error("Deposit token not active")]
DepositTokenNotActive,
#[error("Insufficient global deposit balance")]
InsufficientGlobalDeposit,
#[error("Invalid deposit mint order")]
InvalidDepositMintOrder,
#[error("Amount must be greater than zero")]
ZeroAmount,
#[error("Invalid associated token account")]
InvalidAta,
#[error("Order status is not fully filled")]
OrderNotFullyFilled,
#[error("Payout too small")]
PayoutTooSmall,
#[error("Token account is not empty")]
TokenAccountNotEmpty,
#[error("Lookup table is not closed")]
LookupTableNotClosed,
#[error("Invalid manager")]
InvalidManager,
#[error("Invalid fee range: maker and taker bps must each be between -500 and 500")]
InvalidFeeRange,
#[error("Invalid fee sum: maker + taker bps must be non-negative")]
InvalidFeeSum,
#[error("Invalid fee receiver")]
InvalidFeeReceiver,
#[error("Invalid pubkey: {0}")]
InvalidPubkey(String),
#[error("Scaling error: {0}")]
Scaling(#[from] crate::shared::scaling::ScalingError),
#[error("Order must be signed before converting to submit request")]
UnsignedOrder,
}
pub type SdkResult<T> = Result<T, SdkError>;