//! Account-level capabilities (entitlements) shared across services.
//!
//! Distinct from API-key [`crate::permissions`] (per key) and roles (operational). A user is
//! granted a default set at registration; the platform admin can restrict/grant per user. The
//! effective set is computed in the identity service and propagated to every service as the
//! signed `x-auth-capabilities` header; enforcement is per-endpoint via
//! [`crate::UserContext::require_capability`].

/// Read account data (balances / orders / history).
pub const ACCOUNT_READ: &str = "account.read";
/// Place / cancel spot orders.
pub const SPOT_TRADE: &str = "spot.trade";
/// Crypto deposits.
pub const DEPOSIT_CRYPTO: &str = "deposit.crypto";
/// Crypto withdrawals.
pub const WITHDRAW_CRYPTO: &str = "withdraw.crypto";
/// Internal transfers.
pub const TRANSFER_INTERNAL: &str = "transfer.internal";
/// Create / use API keys.
pub const API_ACCESS: &str = "api.access";
/// Earn / staking.
pub const EARN_STAKE: &str = "earn.stake";
/// Fiat deposits (off by default).
pub const FIAT_DEPOSIT: &str = "fiat.deposit";
/// Fiat withdrawals (off by default).
pub const FIAT_WITHDRAW: &str = "fiat.withdraw";

/// Every known capability, in canonical order.
pub const ALL: &[&str] = &[
    ACCOUNT_READ,
    SPOT_TRADE,
    DEPOSIT_CRYPTO,
    WITHDRAW_CRYPTO,
    TRANSFER_INTERNAL,
    API_ACCESS,
    EARN_STAKE,
    FIAT_DEPOSIT,
    FIAT_WITHDRAW,
];

/// Capabilities granted to every user at registration (everything except fiat, which the admin
/// enables explicitly).
pub const DEFAULT_ON: &[&str] = &[
    ACCOUNT_READ,
    SPOT_TRADE,
    DEPOSIT_CRYPTO,
    WITHDRAW_CRYPTO,
    TRANSFER_INTERNAL,
    API_ACCESS,
    EARN_STAKE,
];

/// True when `cap` is a recognized capability.
pub fn is_valid(cap: &str) -> bool {
    ALL.contains(&cap)
}

/// True when `cap` is on by default at registration.
pub fn is_default_on(cap: &str) -> bool {
    DEFAULT_ON.contains(&cap)
}
