use serde::{Deserialize, Serialize};
use solana_sdk::{pubkey::Pubkey, signature::Signature};

/// TransactionEvent records a transaction submitted by a user via a Regolith Labs app.
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct TransactionEvent {
    /// The signature of the transaction.
    pub sig: Signature,

    /// The signer of the transaction.
    pub signer: Pubkey,

    /// The type of transaction (feature used).
    pub transaction_type: TransactionType,

    /// The app that the transaction was submitted from.
    pub app: AppId,

    /// The timestamp of the transaction.
    pub ts: i64,

    /// The status of the transaction.
    pub status: Option<String>,

    /// The fee collected (in lamports).
    pub fee: Option<i64>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum TransactionType {
    Swap,
    BoostDeposit,
    BoostWithdraw,
    BoostClaim,
    PoolClaim,
    PoolJoin,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum AppId {
    OreWeb,
    OreDesktop,
}

impl std::fmt::Display for AppId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{:?}", self)
    }
}

impl std::fmt::Display for TransactionType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{:?}", self)
    }
}
