use std::fmt;

use serde::Deserialize;

#[derive(Debug, Clone, Deserialize)]
pub struct Account {
    pub id: u64,
    pub name: String,
    pub institution_name: String,
    pub institution_logo: Option<String>,
    pub provider: Provider,
    pub currency: Option<String>,
    pub status: AccountStatus,
}

#[derive(Debug, Clone, Deserialize)]
pub struct AccountList {
    pub accounts: Vec<Account>,
    pub total: u64,
}

#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum Provider {
    #[serde(rename = "gocardless")]
    GoCardless,
    Quiltt,
    Finverse,
    Pluggy,
    #[serde(rename = "lunchmoney")]
    LunchMoney,
    #[serde(rename = "simplefin")]
    SimpleFin,
    Stripe,
    Akahu,
    #[serde(rename = "snaptrade")]
    SnapTrade,
}

#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
pub enum AccountStatus {
    #[serde(rename = "ACTIVE")]
    Active,
    #[serde(rename = "DISCONNECTED")]
    Disconnected,
    #[serde(rename = "ERROR")]
    Error,
}

impl fmt::Display for AccountStatus {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            AccountStatus::Active => write!(f, "ACTIVE"),
            AccountStatus::Disconnected => write!(f, "DISCONNECTED"),
            AccountStatus::Error => write!(f, "ERROR"),
        }
    }
}
