//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpsconverter?language=objc)
#[doc(alias = "CGPSConverterRef")]
#[repr(C)]
pub struct CGPSConverter {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

cf_type!(
    unsafe impl CGPSConverter {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"CGPSConverter"> for CGPSConverter {}
);

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpsconverterbegindocumentcallback?language=objc)
pub type CGPSConverterBeginDocumentCallback = Option<unsafe extern "C-unwind" fn(*mut c_void)>;

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpsconverterenddocumentcallback?language=objc)
pub type CGPSConverterEndDocumentCallback = Option<unsafe extern "C-unwind" fn(*mut c_void, bool)>;

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpsconverterbeginpagecallback?language=objc)
pub type CGPSConverterBeginPageCallback =
    Option<unsafe extern "C-unwind" fn(*mut c_void, usize, NonNull<CFDictionary>)>;

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpsconverterendpagecallback?language=objc)
pub type CGPSConverterEndPageCallback =
    Option<unsafe extern "C-unwind" fn(*mut c_void, usize, NonNull<CFDictionary>)>;

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpsconverterprogresscallback?language=objc)
pub type CGPSConverterProgressCallback = Option<unsafe extern "C-unwind" fn(*mut c_void)>;

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpsconvertermessagecallback?language=objc)
pub type CGPSConverterMessageCallback =
    Option<unsafe extern "C-unwind" fn(*mut c_void, NonNull<CFString>)>;

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpsconverterreleaseinfocallback?language=objc)
pub type CGPSConverterReleaseInfoCallback = Option<unsafe extern "C-unwind" fn(*mut c_void)>;

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgpsconvertercallbacks?language=objc)
#[repr(C)]
#[allow(unpredictable_function_pointer_comparisons)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CGPSConverterCallbacks {
    pub version: c_uint,
    pub beginDocument: CGPSConverterBeginDocumentCallback,
    pub endDocument: CGPSConverterEndDocumentCallback,
    pub beginPage: CGPSConverterBeginPageCallback,
    pub endPage: CGPSConverterEndPageCallback,
    pub noteProgress: CGPSConverterProgressCallback,
    pub noteMessage: CGPSConverterMessageCallback,
    pub releaseInfo: CGPSConverterReleaseInfoCallback,
}

#[cfg(feature = "objc2")]
unsafe impl Encode for CGPSConverterCallbacks {
    const ENCODING: Encoding = Encoding::Struct(
        "CGPSConverterCallbacks",
        &[
            <c_uint>::ENCODING,
            <CGPSConverterBeginDocumentCallback>::ENCODING,
            Encoding::Pointer(&Encoding::Unknown),
            <CGPSConverterBeginPageCallback>::ENCODING,
            <CGPSConverterEndPageCallback>::ENCODING,
            <CGPSConverterProgressCallback>::ENCODING,
            <CGPSConverterMessageCallback>::ENCODING,
            <CGPSConverterReleaseInfoCallback>::ENCODING,
        ],
    );
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for CGPSConverterCallbacks {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

impl CGPSConverter {
    /// # Safety
    ///
    /// - `info` must be a valid pointer or null.
    /// - `callbacks` must be a valid pointer.
    /// - `options` generics must be of the correct type.
    #[doc(alias = "CGPSConverterCreate")]
    #[inline]
    pub unsafe fn new(
        info: *mut c_void,
        callbacks: NonNull<CGPSConverterCallbacks>,
        options: Option<&CFDictionary>,
    ) -> Option<CFRetained<CGPSConverter>> {
        extern "C-unwind" {
            fn CGPSConverterCreate(
                info: *mut c_void,
                callbacks: NonNull<CGPSConverterCallbacks>,
                options: Option<&CFDictionary>,
            ) -> Option<NonNull<CGPSConverter>>;
        }
        let ret = unsafe { CGPSConverterCreate(info, callbacks, options) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// # Safety
    ///
    /// `options` generics must be of the correct type.
    #[doc(alias = "CGPSConverterConvert")]
    #[cfg(all(feature = "CGDataConsumer", feature = "CGDataProvider"))]
    #[inline]
    pub unsafe fn convert(
        &self,
        provider: &CGDataProvider,
        consumer: &CGDataConsumer,
        options: Option<&CFDictionary>,
    ) -> bool {
        extern "C-unwind" {
            fn CGPSConverterConvert(
                converter: &CGPSConverter,
                provider: &CGDataProvider,
                consumer: &CGDataConsumer,
                options: Option<&CFDictionary>,
            ) -> bool;
        }
        unsafe { CGPSConverterConvert(self, provider, consumer, options) }
    }

    #[doc(alias = "CGPSConverterAbort")]
    #[inline]
    pub fn abort(&self) -> bool {
        extern "C-unwind" {
            fn CGPSConverterAbort(converter: &CGPSConverter) -> bool;
        }
        unsafe { CGPSConverterAbort(self) }
    }

    #[doc(alias = "CGPSConverterIsConverting")]
    #[inline]
    pub fn is_converting(&self) -> bool {
        extern "C-unwind" {
            fn CGPSConverterIsConverting(converter: &CGPSConverter) -> bool;
        }
        unsafe { CGPSConverterIsConverting(self) }
    }
}

unsafe impl ConcreteType for CGPSConverter {
    #[doc(alias = "CGPSConverterGetTypeID")]
    #[inline]
    fn type_id() -> CFTypeID {
        extern "C-unwind" {
            fn CGPSConverterGetTypeID() -> CFTypeID;
        }
        unsafe { CGPSConverterGetTypeID() }
    }
}

#[deprecated = "renamed to `CGPSConverter::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CGPSConverterCreate(
    info: *mut c_void,
    callbacks: NonNull<CGPSConverterCallbacks>,
    options: Option<&CFDictionary>,
) -> Option<CFRetained<CGPSConverter>> {
    extern "C-unwind" {
        fn CGPSConverterCreate(
            info: *mut c_void,
            callbacks: NonNull<CGPSConverterCallbacks>,
            options: Option<&CFDictionary>,
        ) -> Option<NonNull<CGPSConverter>>;
    }
    let ret = unsafe { CGPSConverterCreate(info, callbacks, options) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

extern "C-unwind" {
    #[cfg(all(feature = "CGDataConsumer", feature = "CGDataProvider"))]
    #[deprecated = "renamed to `CGPSConverter::convert`"]
    pub fn CGPSConverterConvert(
        converter: &CGPSConverter,
        provider: &CGDataProvider,
        consumer: &CGDataConsumer,
        options: Option<&CFDictionary>,
    ) -> bool;
}

#[deprecated = "renamed to `CGPSConverter::abort`"]
#[inline]
pub extern "C-unwind" fn CGPSConverterAbort(converter: &CGPSConverter) -> bool {
    extern "C-unwind" {
        fn CGPSConverterAbort(converter: &CGPSConverter) -> bool;
    }
    unsafe { CGPSConverterAbort(converter) }
}

#[deprecated = "renamed to `CGPSConverter::is_converting`"]
#[inline]
pub extern "C-unwind" fn CGPSConverterIsConverting(converter: &CGPSConverter) -> bool {
    extern "C-unwind" {
        fn CGPSConverterIsConverting(converter: &CGPSConverter) -> bool;
    }
    unsafe { CGPSConverterIsConverting(converter) }
}
