pub mod response;

use postgres_types::{FromSql, ToSql};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct Transfer {
    pub sig: String,
    pub from_address: String,
    pub to_address: String,
    pub amount: i64,
    pub memo: Option<String>,
    pub transfer_type: TransferType,
    pub ts: i64,
    pub slot: i64,
}

#[derive(Clone, Debug, ToSql, FromSql, Deserialize, Serialize, Eq, PartialEq)]
#[postgres(name = "transfer_type")]
pub enum TransferType {
    #[postgres(name = "CLAIM")]
    #[serde(rename = "CLAIM")]
    Claim,
    #[postgres(name = "MINE")]
    #[serde(rename = "MINE")]
    Mine,
    #[postgres(name = "SPL")]
    #[serde(rename = "SPL")]
    Spl,
}

#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct Supply {
    pub sig: String,
    pub amount: i64,
    pub ts: i64,
    pub slot: i64,
}

#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct Circulating {
    pub sig: String,
    pub amount: i64,
    pub ts: i64,
    pub slot: i64,
}

#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct RewardRate {
    pub sig: String,
    pub amount: i64,
    pub ts: i64,
    pub slot: i64,
}

#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct Difficulty {
    pub sig: String,
    pub value: i64,
    pub ts: i64,
    pub slot: i64,
}

// TODO StopMiner
// TODO SetPowerLevel
// TODO SetAppearance
// TODO SetExplorer
// TODO ExportKey
// TODO DownloadApp
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum AppEvent {
    TopUp,
    StartMiner,
    Claim { amount: u64 },
    Transfer { amount: u64 },
    SetPriorityFee { lamports: u64 },
}

impl AppEvent {
    pub fn to_string(&self) -> String {
        match self {
            AppEvent::TopUp => "Top up",
            AppEvent::StartMiner => "Start miner",
            AppEvent::Claim { amount: _ } => "Claim",
            AppEvent::Transfer { amount: _ } => "Transfer",
            AppEvent::SetPriorityFee { lamports: _ } => "Set priority fee",
        }
        .to_string()
    }
}
