//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern_protocol!(
    /// The delegate method for receiving query results from the NSRunLoop-based queries
    ///
    /// The delegate method called as results are returned from an NSRunLoop-based query.  These results are only partial
    /// and delegate is called repeatedly as results are available.  The incoming result must be retained or copied.  The
    /// array will be released by the NSRunLoop upon return.  Incoming results do not include previous results,
    /// only the most resent results are returned.  inResults can be nil if an error occurs or the query is complete.  If
    /// inResults and inError are nil then the query has completed.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/opendirectory/odquerydelegate?language=objc)
    pub unsafe trait ODQueryDelegate: NSObjectProtocol {
        /// # Safety
        ///
        /// - `in_query` might not allow `None`.
        /// - `in_results` generic should be of the correct type.
        /// - `in_results` might not allow `None`.
        /// - `in_error` might not allow `None`.
        #[unsafe(method(query:foundResults:error:))]
        #[unsafe(method_family = none)]
        unsafe fn query_foundResults_error(
            &self,
            in_query: Option<&ODQuery>,
            in_results: Option<&NSArray>,
            in_error: Option<&NSError>,
        );
    }
);

extern_class!(
    /// Class used for querying OpenDirectory.
    ///
    /// OpenDirectory queries may be used to search for different types of records, e.g. users, groups.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/opendirectory/odquery?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct ODQuery;
);

extern_conformance!(
    unsafe impl NSCopying for ODQuery {}
);

unsafe impl CopyingHelper for ODQuery {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for ODQuery {}
);

impl ODQuery {
    extern_methods!(
        #[cfg(all(
            feature = "CFOpenDirectory",
            feature = "CFOpenDirectoryConstants",
            feature = "ODNode"
        ))]
        /// Creates an autoreleased query with the node using the parameters provided
        ///
        /// Creates an autoreleased query with the node using the supplied query parameters.  Some parameters
        /// can either be NSString or NSData or an NSArray of either NSString or NSData.  Passing nil for
        /// returnAttributes is equivalent to passing kODAttributeTypeStandardOnly.  outError is optional parameter,
        /// nil can be passed if error details are not needed.
        ///
        /// # Safety
        ///
        /// - `in_node` might not allow `None`.
        /// - `in_record_type_or_list` should be of the correct type.
        /// - `in_record_type_or_list` might not allow `None`.
        /// - `in_attribute` might not allow `None`.
        /// - `in_query_value_or_list` should be of the correct type.
        /// - `in_query_value_or_list` might not allow `None`.
        /// - `in_return_attribute_or_list` should be of the correct type.
        /// - `in_return_attribute_or_list` might not allow `None`.
        /// - `out_error` might not allow `None`.
        #[unsafe(method(queryWithNode:forRecordTypes:attribute:matchType:queryValues:returnAttributes:maximumResults:error:))]
        #[unsafe(method_family = none)]
        pub unsafe fn queryWithNode_forRecordTypes_attribute_matchType_queryValues_returnAttributes_maximumResults_error(
            in_node: Option<&ODNode>,
            in_record_type_or_list: Option<&AnyObject>,
            in_attribute: Option<&ODAttributeType>,
            in_match_type: ODMatchType,
            in_query_value_or_list: Option<&AnyObject>,
            in_return_attribute_or_list: Option<&AnyObject>,
            in_maximum_results: NSInteger,
            out_error: Option<&mut Option<Retained<NSError>>>,
        ) -> Option<Retained<ODQuery>>;

        #[cfg(all(
            feature = "CFOpenDirectory",
            feature = "CFOpenDirectoryConstants",
            feature = "ODNode"
        ))]
        /// Creates a query with the node using the parameters provided
        ///
        /// Creates a query with the node using the supplied query parameters.  Some parameters
        /// can either be NSString or NSData or an NSArray of either NSString or NSData.  Passing nil for
        /// returnAttributes is equivalent to passing kODAttributeTypeStandardOnly. outError is optional parameter,
        /// nil can be passed if error details are not needed.
        ///
        /// # Safety
        ///
        /// - `in_node` might not allow `None`.
        /// - `in_record_type_or_list` should be of the correct type.
        /// - `in_record_type_or_list` might not allow `None`.
        /// - `in_attribute` might not allow `None`.
        /// - `in_query_value_or_list` should be of the correct type.
        /// - `in_query_value_or_list` might not allow `None`.
        /// - `in_return_attribute_or_list` should be of the correct type.
        /// - `in_return_attribute_or_list` might not allow `None`.
        /// - `out_error` might not allow `None`.
        #[unsafe(method(initWithNode:forRecordTypes:attribute:matchType:queryValues:returnAttributes:maximumResults:error:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithNode_forRecordTypes_attribute_matchType_queryValues_returnAttributes_maximumResults_error(
            this: Allocated<Self>,
            in_node: Option<&ODNode>,
            in_record_type_or_list: Option<&AnyObject>,
            in_attribute: Option<&ODAttributeType>,
            in_match_type: ODMatchType,
            in_query_value_or_list: Option<&AnyObject>,
            in_return_attribute_or_list: Option<&AnyObject>,
            in_maximum_results: NSInteger,
            out_error: Option<&mut Option<Retained<NSError>>>,
        ) -> Option<Retained<Self>>;

        /// Returns results from a provided ODQuery synchronously
        ///
        /// Returns results from a provided ODQuery synchronously.  Passing NO to inAllowPartialResults
        /// will block the call until all results are returned or an error occurs.  YES can be passed at any time
        /// even if previous calls were made with NO.  outError is optional parameter, nil can be passed if error
        /// details are not needed.
        ///
        /// # Safety
        ///
        /// `out_error` might not allow `None`.
        #[unsafe(method(resultsAllowingPartial:error:))]
        #[unsafe(method_family = none)]
        pub unsafe fn resultsAllowingPartial_error(
            &self,
            in_allow_partial_results: bool,
            out_error: Option<&mut Option<Retained<NSError>>>,
        ) -> Option<Retained<NSArray>>;

        /// The currently set delegate
        ///
        /// The query delegate which will receive asynchronous query results.
        ///
        /// # Safety
        ///
        /// This is not retained internally, you must ensure the object is still alive.
        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn ODQueryDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// # Safety
        ///
        /// - `delegate` might not allow `None`.
        /// - This is unretained, you must ensure the object is kept alive while in use.
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn ODQueryDelegate>>);

        /// Adds the query object to the specified NSRunLoop to receive asynchronous results
        ///
        /// Adds the query object to the specified NSRunLoop to receive asynchronous results.  A delegate must be set
        /// in advance otherwise results may be lost due to the lack of a receiver.
        ///
        /// # Safety
        ///
        /// - `in_run_loop` possibly has additional threading requirements.
        /// - `in_run_loop` might not allow `None`.
        /// - `in_mode` might not allow `None`.
        #[unsafe(method(scheduleInRunLoop:forMode:))]
        #[unsafe(method_family = none)]
        pub unsafe fn scheduleInRunLoop_forMode(
            &self,
            in_run_loop: Option<&NSRunLoop>,
            in_mode: Option<&NSString>,
        );

        /// Removes the query object from the specified NSRunLoop
        ///
        /// Removes the query object from the specified NSRunLoop.
        ///
        /// # Safety
        ///
        /// - `in_run_loop` possibly has additional threading requirements.
        /// - `in_run_loop` might not allow `None`.
        /// - `in_mode` might not allow `None`.
        #[unsafe(method(removeFromRunLoop:forMode:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeFromRunLoop_forMode(
            &self,
            in_run_loop: Option<&NSRunLoop>,
            in_mode: Option<&NSString>,
        );

        /// Will dispose of any results and restart the query.
        ///
        /// Will dispose of any results and restart the query for subsequent resultsAllowingPartial: calls.  If the query
        /// is currently scheduled on a RunLoop, then the delegate will be called with inResults == nil and
        /// [inError code] == kODErrorQuerySynchronize and [inError domain] == ODFrameworkErrorDomain, signifying that
        /// all existing results should be thrown away in preparation for new results.
        #[unsafe(method(synchronize))]
        #[unsafe(method_family = none)]
        pub unsafe fn synchronize(&self);

        /// The NSOperationQueue on which asynchronous results are delivered to the delegate.
        ///
        /// The NSOperationQueue on which asynchronous results are delivered to the delegate.
        #[unsafe(method(operationQueue))]
        #[unsafe(method_family = none)]
        pub unsafe fn operationQueue(&self) -> Option<Retained<NSOperationQueue>>;

        /// Setter for [`operationQueue`][Self::operationQueue].
        ///
        /// # Safety
        ///
        /// - `operation_queue` possibly has additional threading requirements.
        /// - `operation_queue` might not allow `None`.
        #[unsafe(method(setOperationQueue:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setOperationQueue(&self, operation_queue: Option<&NSOperationQueue>);
    );
}

/// Methods declared on superclass `NSObject`.
impl ODQuery {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}
