//! # Project constants

use crate::models::accounts::AccountType;

/// Length of generated tokens
pub const TOKENS_LEN: usize = 50;

/// Header used to authenticate API requests made using a token
pub const API_TOKEN_HEADER: &str = "X-Auth-Token";

/// Max token validity
pub const API_TOKEN_JWT_MAX_DURATION: u64 = 15 * 60;

/// Session-specific constants
pub mod sessions {
    /// OpenID auth session state key
    pub const OIDC_STATE_KEY: &str = "oidc-state";
    /// OpenID auth remote IP address
    pub const OIDC_REMOTE_IP: &str = "oidc-remote-ip";
    /// Authenticated ID
    pub const USER_ID: &str = "uid";
}

/// Maximum uploaded file size (15MB)
pub const MAX_UPLOAD_FILE_SIZE: usize = 15 * 1024 * 1024;

/// Minimum elapsed time before a file can be deleted by garbage collector (2 hours)
pub const MIN_FILE_LIFETIME: u64 = 3600 * 2;

/// Description of an account type
#[derive(serde::Serialize, Debug)]
pub struct AccountTypeDesc {
    label: &'static str,
    code: AccountType,
    icon: &'static str,
}

/// Enumeration of accounts types
pub const ACCOUNT_TYPES: [AccountTypeDesc; 3] = [
    AccountTypeDesc {
        label: "Cash",
        code: AccountType::Cash,
        icon: include_str!("../assets/cash.svg"),
    },
    AccountTypeDesc {
        label: "Bank",
        code: AccountType::Bank,
        icon: include_str!("../assets/credit-card.svg"),
    },
    AccountTypeDesc {
        label: "Saving",
        code: AccountType::Saving,
        icon: include_str!("../assets/saving.svg"),
    },
];

/// ZIP export paths
pub mod zip_export {
    /// Accounts file path inside archive
    pub const ACCOUNTS_FILE: &str = "accounts.json";

    /// Movements file path inside archive
    pub const MOVEMENTS_FILE: &str = "movements.json";

    /// Files list file path inside archive
    pub const FILES_FILE: &str = "files.json";

    /// Files directory inside archive
    pub const FILES_DIR: &str = "files/";

    /// Inbox file path inside archive
    pub const INBOX_FILE: &str = "inbox.json";
}
