//! 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/cgdataconsumer?language=objc)
#[doc(alias = "CGDataConsumerRef")]
#[repr(C)]
pub struct CGDataConsumer {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

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

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

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

/// [Apple's documentation](https://developer.apple.com/documentation/coregraphics/cgdataconsumercallbacks?language=objc)
#[repr(C)]
#[allow(unpredictable_function_pointer_comparisons)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CGDataConsumerCallbacks {
    pub putBytes: CGDataConsumerPutBytesCallback,
    pub releaseConsumer: CGDataConsumerReleaseInfoCallback,
}

#[cfg(feature = "objc2")]
unsafe impl Encode for CGDataConsumerCallbacks {
    const ENCODING: Encoding = Encoding::Struct(
        "CGDataConsumerCallbacks",
        &[
            <CGDataConsumerPutBytesCallback>::ENCODING,
            <CGDataConsumerReleaseInfoCallback>::ENCODING,
        ],
    );
}

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

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

impl CGDataConsumer {
    /// # Safety
    ///
    /// - `info` must be a valid pointer or null.
    /// - `cbks` must be a valid pointer or null.
    #[doc(alias = "CGDataConsumerCreate")]
    #[inline]
    pub unsafe fn new(
        info: *mut c_void,
        cbks: *const CGDataConsumerCallbacks,
    ) -> Option<CFRetained<CGDataConsumer>> {
        extern "C-unwind" {
            fn CGDataConsumerCreate(
                info: *mut c_void,
                cbks: *const CGDataConsumerCallbacks,
            ) -> Option<NonNull<CGDataConsumer>>;
        }
        let ret = unsafe { CGDataConsumerCreate(info, cbks) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    #[doc(alias = "CGDataConsumerCreateWithURL")]
    #[inline]
    pub fn with_url(url: Option<&CFURL>) -> Option<CFRetained<CGDataConsumer>> {
        extern "C-unwind" {
            fn CGDataConsumerCreateWithURL(url: Option<&CFURL>) -> Option<NonNull<CGDataConsumer>>;
        }
        let ret = unsafe { CGDataConsumerCreateWithURL(url) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    #[doc(alias = "CGDataConsumerCreateWithCFData")]
    #[inline]
    pub fn with_cf_data(data: Option<&CFMutableData>) -> Option<CFRetained<CGDataConsumer>> {
        extern "C-unwind" {
            fn CGDataConsumerCreateWithCFData(
                data: Option<&CFMutableData>,
            ) -> Option<NonNull<CGDataConsumer>>;
        }
        let ret = unsafe { CGDataConsumerCreateWithCFData(data) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }
}

#[deprecated = "renamed to `CGDataConsumer::new`"]
#[inline]
pub unsafe extern "C-unwind" fn CGDataConsumerCreate(
    info: *mut c_void,
    cbks: *const CGDataConsumerCallbacks,
) -> Option<CFRetained<CGDataConsumer>> {
    extern "C-unwind" {
        fn CGDataConsumerCreate(
            info: *mut c_void,
            cbks: *const CGDataConsumerCallbacks,
        ) -> Option<NonNull<CGDataConsumer>>;
    }
    let ret = unsafe { CGDataConsumerCreate(info, cbks) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[deprecated = "renamed to `CGDataConsumer::with_url`"]
#[inline]
pub extern "C-unwind" fn CGDataConsumerCreateWithURL(
    url: Option<&CFURL>,
) -> Option<CFRetained<CGDataConsumer>> {
    extern "C-unwind" {
        fn CGDataConsumerCreateWithURL(url: Option<&CFURL>) -> Option<NonNull<CGDataConsumer>>;
    }
    let ret = unsafe { CGDataConsumerCreateWithURL(url) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[deprecated = "renamed to `CGDataConsumer::with_cf_data`"]
#[inline]
pub extern "C-unwind" fn CGDataConsumerCreateWithCFData(
    data: Option<&CFMutableData>,
) -> Option<CFRetained<CGDataConsumer>> {
    extern "C-unwind" {
        fn CGDataConsumerCreateWithCFData(
            data: Option<&CFMutableData>,
        ) -> Option<NonNull<CGDataConsumer>>;
    }
    let ret = unsafe { CGDataConsumerCreateWithCFData(data) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}
