#![deny(clippy::cargo)]
use serde::{Deserialize, Serialize};

/// User object
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct User {
    pub name: String,
    pub id: u128,
}

/// May be returned for any endpoint when said endpoint has a failure
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct ApiError {
    pub error: String,
}

/// Returned by the /auth/token and /auth/totp routes. Always use /auth/token first, you will be granted a temporary Bearer token if needs_totp is true, you can then call /auth/totp with the Bearer token and TOTP authcode.
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct LoginResponse {
    pub token: String,
    pub needs_totp: bool,
}

/// For requesting to the /auth/totp route. You must also have a temporary TOTP authtoken first!
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct TotpRequest {
    pub code: String,
}

#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct MessageCreate {
    pub contents: String,
    pub author: User,
    pub created: u64,
}

#[derive(Serialize, Deserialize)]
pub struct UserCreate {
    pub email: String,
    pub name: String,
    pub password: String,
    pub pubkey: String,
    pub privkey: String,
    pub security_level: UserSecurityLevel,
}

#[derive(Serialize, Deserialize)]
pub enum UserSecurityLevel {
    Max,
    Reasonable,
    Low,
}

impl ToString for UserSecurityLevel {
    fn to_string(&self) -> String {
        match self {
            Self::Max => "Max".to_string(),
            Self::Reasonable => "Reasonable".to_string(),
            Self::Low => "Low".to_string(),
        }
    }
}
