objc2-photos 0.3.2

Bindings to the Photos/PhotoKit framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
#[cfg(feature = "dispatch2")]
use dispatch2::*;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/photos/phauthorizationstatus?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct PHAuthorizationStatus(pub NSInteger);
impl PHAuthorizationStatus {
    #[doc(alias = "PHAuthorizationStatusNotDetermined")]
    pub const NotDetermined: Self = Self(0);
    #[doc(alias = "PHAuthorizationStatusRestricted")]
    pub const Restricted: Self = Self(1);
    #[doc(alias = "PHAuthorizationStatusDenied")]
    pub const Denied: Self = Self(2);
    #[doc(alias = "PHAuthorizationStatusAuthorized")]
    pub const Authorized: Self = Self(3);
    #[doc(alias = "PHAuthorizationStatusLimited")]
    pub const Limited: Self = Self(4);
}

unsafe impl Encode for PHAuthorizationStatus {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for PHAuthorizationStatus {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/photos/phaccesslevel?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct PHAccessLevel(pub NSInteger);
impl PHAccessLevel {
    #[doc(alias = "PHAccessLevelAddOnly")]
    pub const AddOnly: Self = Self(1);
    #[doc(alias = "PHAccessLevelReadWrite")]
    pub const ReadWrite: Self = Self(2);
}

unsafe impl Encode for PHAccessLevel {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for PHAccessLevel {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/photos/phphotolibrarychangeobserver?language=objc)
    pub unsafe trait PHPhotoLibraryChangeObserver: NSObjectProtocol {
        #[cfg(feature = "PHChange")]
        #[unsafe(method(photoLibraryDidChange:))]
        #[unsafe(method_family = none)]
        unsafe fn photoLibraryDidChange(&self, change_instance: &PHChange);
    }
);

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/photos/phphotolibraryavailabilityobserver?language=objc)
    pub unsafe trait PHPhotoLibraryAvailabilityObserver: NSObjectProtocol {
        #[unsafe(method(photoLibraryDidBecomeUnavailable:))]
        #[unsafe(method_family = none)]
        unsafe fn photoLibraryDidBecomeUnavailable(&self, photo_library: &PHPhotoLibrary);
    }
);

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

unsafe impl Send for PHPhotoLibrary {}

unsafe impl Sync for PHPhotoLibrary {}

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

impl PHPhotoLibrary {
    extern_methods!(
        #[unsafe(method(sharedPhotoLibrary))]
        #[unsafe(method_family = none)]
        pub unsafe fn sharedPhotoLibrary() -> Retained<PHPhotoLibrary>;

        /// Replaces
        /// `+authorizationStatus`to support add-only/read-write access level status
        #[unsafe(method(authorizationStatusForAccessLevel:))]
        #[unsafe(method_family = none)]
        pub unsafe fn authorizationStatusForAccessLevel(
            access_level: PHAccessLevel,
        ) -> PHAuthorizationStatus;

        #[cfg(feature = "block2")]
        #[unsafe(method(requestAuthorizationForAccessLevel:handler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn requestAuthorizationForAccessLevel_handler(
            access_level: PHAccessLevel,
            handler: &block2::DynBlock<dyn Fn(PHAuthorizationStatus)>,
        );

        /// Deprecated and replaced by authorizationStatusForAccessLevel:, will return
        /// `PHAuthorizationStatusAuthorized`if the user has chosen limited photo library access
        #[deprecated]
        #[unsafe(method(authorizationStatus))]
        #[unsafe(method_family = none)]
        pub unsafe fn authorizationStatus() -> PHAuthorizationStatus;

        #[cfg(feature = "block2")]
        #[deprecated]
        #[unsafe(method(requestAuthorization:))]
        #[unsafe(method_family = none)]
        pub unsafe fn requestAuthorization(
            handler: &block2::DynBlock<dyn Fn(PHAuthorizationStatus)>,
        );

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

        #[unsafe(method(registerAvailabilityObserver:))]
        #[unsafe(method_family = none)]
        pub unsafe fn registerAvailabilityObserver(
            &self,
            observer: &ProtocolObject<dyn PHPhotoLibraryAvailabilityObserver>,
        );

        #[unsafe(method(unregisterAvailabilityObserver:))]
        #[unsafe(method_family = none)]
        pub unsafe fn unregisterAvailabilityObserver(
            &self,
            observer: &ProtocolObject<dyn PHPhotoLibraryAvailabilityObserver>,
        );

        #[cfg(all(feature = "block2", feature = "dispatch2"))]
        /// # Safety
        ///
        /// `change_block` must be a valid pointer.
        #[unsafe(method(performChanges:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn performChanges_completionHandler(
            &self,
            change_block: dispatch_block_t,
            completion_handler: Option<&block2::DynBlock<dyn Fn(Bool, *mut NSError)>>,
        );

        #[cfg(feature = "dispatch2")]
        /// # Safety
        ///
        /// `change_block` must be a valid pointer.
        #[unsafe(method(performChangesAndWait:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn performChangesAndWait_error(
            &self,
            change_block: dispatch_block_t,
        ) -> Result<(), Retained<NSError>>;

        #[unsafe(method(registerChangeObserver:))]
        #[unsafe(method_family = none)]
        pub unsafe fn registerChangeObserver(
            &self,
            observer: &ProtocolObject<dyn PHPhotoLibraryChangeObserver>,
        );

        #[unsafe(method(unregisterChangeObserver:))]
        #[unsafe(method_family = none)]
        pub unsafe fn unregisterChangeObserver(
            &self,
            observer: &ProtocolObject<dyn PHPhotoLibraryChangeObserver>,
        );

        #[cfg(all(
            feature = "PHPersistentChangeFetchResult",
            feature = "PHPersistentChangeToken"
        ))]
        #[unsafe(method(fetchPersistentChangesSinceToken:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn fetchPersistentChangesSinceToken_error(
            &self,
            token: &PHPersistentChangeToken,
        ) -> Result<Retained<PHPersistentChangeFetchResult>, Retained<NSError>>;

        #[cfg(feature = "PHPersistentChangeToken")]
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(currentChangeToken))]
        #[unsafe(method_family = none)]
        pub unsafe fn currentChangeToken(&self) -> Retained<PHPersistentChangeToken>;
    );
}

/// Methods declared on superclass `NSObject`.
impl PHPhotoLibrary {
    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>;
    );
}