pdk-script 1.9.0-alpha.1

PDK Script
Documentation
// Copyright (c) 2026, Salesforce, Inc.,
// All rights reserved.
// For full license text, see the LICENSE.txt file

use std::collections::HashMap;

use crate::Value;

/// Binding for the top-level `authentication` variable.
pub trait AuthenticationBinding {
    /// Returns the `authentication.clientId` value.
    fn client_id(&self) -> Option<String>;

    /// Returns the `authentication.clientName` value.
    fn client_name(&self) -> Option<String>;

    /// Returns the `authentication.principal` value.
    fn principal(&self) -> Option<String>;

    /// Returns the `authentication.properties` value.
    fn properties(&self) -> Option<Value>;

    /// Returns the `authentication.properties` value as a map.
    fn properties_map(&self) -> HashMap<String, Value>;
}

impl<K: AuthenticationBinding> AuthenticationBinding for Option<K> {
    fn client_id(&self) -> Option<String> {
        self.as_ref().and_then(K::client_id)
    }

    fn client_name(&self) -> Option<String> {
        self.as_ref().and_then(K::client_name)
    }

    fn principal(&self) -> Option<String> {
        self.as_ref().and_then(K::principal)
    }

    fn properties(&self) -> Option<Value> {
        self.as_ref().and_then(K::properties)
    }

    fn properties_map(&self) -> HashMap<String, Value> {
        self.as_ref().map(K::properties_map).unwrap_or_default()
    }
}