//! 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::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nserrordomain?language=objc)
#[cfg(feature = "NSString")]
pub type NSErrorDomain = NSString;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nscocoaerrordomain?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSCocoaErrorDomain: &'static NSErrorDomain;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsposixerrordomain?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSPOSIXErrorDomain: &'static NSErrorDomain;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsosstatuserrordomain?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSOSStatusErrorDomain: &'static NSErrorDomain;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsmacherrordomain?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSMachErrorDomain: &'static NSErrorDomain;
}

/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nserroruserinfokey?language=objc)
#[cfg(feature = "NSString")]
pub type NSErrorUserInfoKey = NSString;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsunderlyingerrorkey?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSUnderlyingErrorKey: &'static NSErrorUserInfoKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsmultipleunderlyingerrorskey?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSMultipleUnderlyingErrorsKey: &'static NSErrorUserInfoKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nslocalizeddescriptionkey?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSLocalizedDescriptionKey: &'static NSErrorUserInfoKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nslocalizedfailurereasonerrorkey?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSLocalizedFailureReasonErrorKey: &'static NSErrorUserInfoKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nslocalizedrecoverysuggestionerrorkey?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSLocalizedRecoverySuggestionErrorKey: &'static NSErrorUserInfoKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nslocalizedrecoveryoptionserrorkey?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSLocalizedRecoveryOptionsErrorKey: &'static NSErrorUserInfoKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsrecoveryattemptererrorkey?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSRecoveryAttempterErrorKey: &'static NSErrorUserInfoKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nshelpanchorerrorkey?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSHelpAnchorErrorKey: &'static NSErrorUserInfoKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsdebugdescriptionerrorkey?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSDebugDescriptionErrorKey: &'static NSErrorUserInfoKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nslocalizedfailureerrorkey?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSLocalizedFailureErrorKey: &'static NSErrorUserInfoKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsstringencodingerrorkey?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSStringEncodingErrorKey: &'static NSErrorUserInfoKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlerrorkey?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSURLErrorKey: &'static NSErrorUserInfoKey;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsfilepatherrorkey?language=objc)
    #[cfg(feature = "NSString")]
    pub static NSFilePathErrorKey: &'static NSErrorUserInfoKey;
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nserror?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(PartialEq, Eq, Hash)]
    pub struct NSError;
);

unsafe impl Send for NSError {}

unsafe impl Sync for NSError {}

#[cfg(feature = "objc2-core-foundation")]
impl AsRef<NSError> for CFError {
    #[inline]
    fn as_ref(&self) -> &NSError {
        unsafe { &*((self as *const Self).cast()) }
    }
}

#[cfg(feature = "objc2-core-foundation")]
impl AsRef<CFError> for NSError {
    #[inline]
    fn as_ref(&self) -> &CFError {
        unsafe { &*((self as *const Self).cast()) }
    }
}

#[cfg(feature = "NSObject")]
extern_conformance!(
    unsafe impl NSCoding for NSError {}
);

#[cfg(feature = "NSObject")]
extern_conformance!(
    unsafe impl NSCopying for NSError {}
);

#[cfg(feature = "NSObject")]
unsafe impl CopyingHelper for NSError {
    type Result = Self;
}

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

#[cfg(feature = "NSObject")]
extern_conformance!(
    unsafe impl NSSecureCoding for NSError {}
);

impl NSError {
    extern_methods!(
        #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
        /// # Safety
        ///
        /// `dict` generic should be of the correct type.
        #[unsafe(method(initWithDomain:code:userInfo:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithDomain_code_userInfo(
            this: Allocated<Self>,
            domain: &NSErrorDomain,
            code: NSInteger,
            dict: Option<&NSDictionary<NSErrorUserInfoKey, AnyObject>>,
        ) -> Retained<Self>;

        #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
        /// # Safety
        ///
        /// `dict` generic should be of the correct type.
        #[unsafe(method(errorWithDomain:code:userInfo:))]
        #[unsafe(method_family = none)]
        pub unsafe fn errorWithDomain_code_userInfo(
            domain: &NSErrorDomain,
            code: NSInteger,
            dict: Option<&NSDictionary<NSErrorUserInfoKey, AnyObject>>,
        ) -> Retained<Self>;

        #[cfg(feature = "NSString")]
        #[unsafe(method(domain))]
        #[unsafe(method_family = none)]
        pub fn domain(&self) -> Retained<NSErrorDomain>;

        #[unsafe(method(code))]
        #[unsafe(method_family = none)]
        pub fn code(&self) -> NSInteger;

        #[cfg(all(feature = "NSDictionary", feature = "NSString"))]
        #[unsafe(method(userInfo))]
        #[unsafe(method_family = none)]
        pub fn userInfo(&self) -> Retained<NSDictionary<NSErrorUserInfoKey, AnyObject>>;

        #[cfg(feature = "NSString")]
        #[unsafe(method(localizedDescription))]
        #[unsafe(method_family = none)]
        pub fn localizedDescription(&self) -> Retained<NSString>;

        #[cfg(feature = "NSString")]
        #[unsafe(method(localizedFailureReason))]
        #[unsafe(method_family = none)]
        pub fn localizedFailureReason(&self) -> Option<Retained<NSString>>;

        #[cfg(feature = "NSString")]
        #[unsafe(method(localizedRecoverySuggestion))]
        #[unsafe(method_family = none)]
        pub fn localizedRecoverySuggestion(&self) -> Option<Retained<NSString>>;

        #[cfg(all(feature = "NSArray", feature = "NSString"))]
        #[unsafe(method(localizedRecoveryOptions))]
        #[unsafe(method_family = none)]
        pub fn localizedRecoveryOptions(&self) -> Option<Retained<NSArray<NSString>>>;

        #[unsafe(method(recoveryAttempter))]
        #[unsafe(method_family = none)]
        pub fn recoveryAttempter(&self) -> Option<Retained<AnyObject>>;

        #[cfg(feature = "NSString")]
        #[unsafe(method(helpAnchor))]
        #[unsafe(method_family = none)]
        pub fn helpAnchor(&self) -> Option<Retained<NSString>>;

        #[cfg(feature = "NSArray")]
        #[unsafe(method(underlyingErrors))]
        #[unsafe(method_family = none)]
        pub fn underlyingErrors(&self) -> Retained<NSArray<NSError>>;

        #[cfg(all(feature = "NSString", feature = "block2"))]
        /// # Safety
        ///
        /// `provider` block must be sendable.
        #[unsafe(method(setUserInfoValueProviderForDomain:provider:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setUserInfoValueProviderForDomain_provider(
            error_domain: &NSErrorDomain,
            provider: Option<
                &block2::DynBlock<
                    dyn Fn(NonNull<NSError>, NonNull<NSErrorUserInfoKey>) -> *mut AnyObject,
                >,
            >,
        );

        #[cfg(all(feature = "NSString", feature = "block2"))]
        /// # Safety
        ///
        /// The returned block must be sendable.
        #[unsafe(method(userInfoValueProviderForDomain:))]
        #[unsafe(method_family = none)]
        pub unsafe fn userInfoValueProviderForDomain(
            error_domain: &NSErrorDomain,
        ) -> *mut block2::DynBlock<
            dyn Fn(NonNull<NSError>, NonNull<NSErrorUserInfoKey>) -> *mut AnyObject,
        >;
    );
}

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

mod private_NSObjectNSErrorRecoveryAttempting {
    pub trait Sealed {}
}

/// Category "NSErrorRecoveryAttempting" on [`NSObject`].
#[doc(alias = "NSErrorRecoveryAttempting")]
pub unsafe trait NSObjectNSErrorRecoveryAttempting:
    ClassType + Sized + private_NSObjectNSErrorRecoveryAttempting::Sealed
{
    extern_methods!(
        /// # Safety
        ///
        /// - `delegate` should be of the correct type.
        /// - `did_recover_selector` must be a valid selector.
        /// - `context_info` must be a valid pointer or null.
        #[unsafe(method(attemptRecoveryFromError:optionIndex:delegate:didRecoverSelector:contextInfo:))]
        #[unsafe(method_family = none)]
        unsafe fn attemptRecoveryFromError_optionIndex_delegate_didRecoverSelector_contextInfo(
            &self,
            error: &NSError,
            recovery_option_index: NSUInteger,
            delegate: Option<&AnyObject>,
            did_recover_selector: Option<Sel>,
            context_info: *mut c_void,
        );

        #[unsafe(method(attemptRecoveryFromError:optionIndex:))]
        #[unsafe(method_family = none)]
        fn attemptRecoveryFromError_optionIndex(
            &self,
            error: &NSError,
            recovery_option_index: NSUInteger,
        ) -> bool;
    );
}

impl private_NSObjectNSErrorRecoveryAttempting::Sealed for NSObject {}
unsafe impl NSObjectNSErrorRecoveryAttempting for NSObject {}
