//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ptr::NonNull;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;

use crate::*;

extern "C" {
    /// is the default type of ODSessionRef used if there is no need to create a specific reference
    ///
    /// is the default type of ODSessionRef used if there is no need to create a specific reference
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/opendirectory/kodsessiondefault?language=objc)
    pub static kODSessionDefault: Option<&'static ODSessionRef>;
}

#[cfg(feature = "objc2-core-foundation")]
unsafe impl ConcreteType for ODSessionRef {
    /// Standard GetTypeID function support for CF-based objects
    ///
    /// Returns the typeID for ODSession objects
    ///
    /// Returns: a valid CFTypeID for the ODSession object
    #[doc(alias = "ODSessionGetTypeID")]
    #[inline]
    fn type_id() -> CFTypeID {
        extern "C-unwind" {
            fn ODSessionGetTypeID() -> CFTypeID;
        }
        unsafe { ODSessionGetTypeID() }
    }
}

impl ODSessionRef {
    /// Creates an ODSession object to be passed to ODNode functions
    ///
    /// Creates an ODSession object to be passed to ODNode functions.
    ///
    /// Parameter `allocator`: a memory allocator to use for this object
    ///
    /// Parameter `options`: a CFDictionary of options associated with this ODSession.  This is typically NULL
    /// unless caller needs to proxy to another host.
    ///
    /// If proxy is required then a dictionary with keys should be:
    /// Key                             Value
    /// kODSessionProxyAddress        CFString(hostname or IP)
    /// kODSessionProxyPort           CFNumber(IP port, should not be set as it will default)
    /// kODSessionProxyUsername       CFString(username)
    /// kODSessionProxyPassword       CFString(password)
    ///
    /// Parameter `error`: an optional CFErrorRef reference for error details
    ///
    /// Returns: a valid ODSessionRef object or NULL if it cannot be created. Pass reference to CFErrorRef to
    /// get error details
    ///
    /// # Safety
    ///
    /// - `allocator` might not allow `None`.
    /// - `options` generics must be of the correct type.
    /// - `options` might not allow `None`.
    /// - `error` must be a valid pointer.
    #[doc(alias = "ODSessionCreate")]
    #[cfg(feature = "objc2-core-foundation")]
    #[inline]
    pub unsafe fn new(
        allocator: Option<&CFAllocator>,
        options: Option<&CFDictionary>,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<ODSessionRef>> {
        extern "C-unwind" {
            fn ODSessionCreate(
                allocator: Option<&CFAllocator>,
                options: Option<&CFDictionary>,
                error: *mut *mut CFError,
            ) -> Option<NonNull<ODSessionRef>>;
        }
        let ret = unsafe { ODSessionCreate(allocator, options, error) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Returns the node names that are registered on this ODSession
    ///
    /// Returns the node names that are registered on this ODSession
    ///
    /// Parameter `allocator`: a memory allocator to use for this object
    ///
    /// Parameter `session`: an ODSessionRef, either kODSessionDefault or a valid ODSessionRef can be passed
    ///
    /// Parameter `error`: an optional CFErrorRef reference for error details
    ///
    /// Returns: a valid CFArrayRef of node names that can be opened on the session reference
    ///
    /// # Safety
    ///
    /// - `allocator` might not allow `None`.
    /// - `session` might not allow `None`.
    /// - `error` must be a valid pointer.
    #[doc(alias = "ODSessionCopyNodeNames")]
    #[cfg(feature = "objc2-core-foundation")]
    #[inline]
    pub unsafe fn node_names(
        allocator: Option<&CFAllocator>,
        session: Option<&ODSessionRef>,
        error: *mut *mut CFError,
    ) -> Option<CFRetained<CFArray>> {
        extern "C-unwind" {
            fn ODSessionCopyNodeNames(
                allocator: Option<&CFAllocator>,
                session: Option<&ODSessionRef>,
                error: *mut *mut CFError,
            ) -> Option<NonNull<CFArray>>;
        }
        let ret = unsafe { ODSessionCopyNodeNames(allocator, session, error) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }
}

#[cfg(feature = "objc2-core-foundation")]
#[deprecated = "renamed to `ODSessionRef::new`"]
#[inline]
pub unsafe extern "C-unwind" fn ODSessionCreate(
    allocator: Option<&CFAllocator>,
    options: Option<&CFDictionary>,
    error: *mut *mut CFError,
) -> Option<CFRetained<ODSessionRef>> {
    extern "C-unwind" {
        fn ODSessionCreate(
            allocator: Option<&CFAllocator>,
            options: Option<&CFDictionary>,
            error: *mut *mut CFError,
        ) -> Option<NonNull<ODSessionRef>>;
    }
    let ret = unsafe { ODSessionCreate(allocator, options, error) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[cfg(feature = "objc2-core-foundation")]
#[deprecated = "renamed to `ODSessionRef::node_names`"]
#[inline]
pub unsafe extern "C-unwind" fn ODSessionCopyNodeNames(
    allocator: Option<&CFAllocator>,
    session: Option<&ODSessionRef>,
    error: *mut *mut CFError,
) -> Option<CFRetained<CFArray>> {
    extern "C-unwind" {
        fn ODSessionCopyNodeNames(
            allocator: Option<&CFAllocator>,
            session: Option<&ODSessionRef>,
            error: *mut *mut CFError,
        ) -> Option<NonNull<CFArray>>;
    }
    let ret = unsafe { ODSessionCopyNodeNames(allocator, session, error) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
