// This file was generated by gir (https://github.com/gtk-rs/gir)
// from ../gir-files
// from ../pps-girs
// DO NOT EDIT

use crate::ffi;
use glib::{prelude::*, translate::*};

glib::wrapper! {
    #[doc(alias = "PpsAttachment")]
    pub struct Attachment(Object<ffi::PpsAttachment, ffi::PpsAttachmentClass>);

    match fn {
        type_ => || ffi::pps_attachment_get_type(),
    }
}

impl Attachment {
    pub const NONE: Option<&'static Attachment> = None;

    //#[doc(alias = "pps_attachment_new")]
    //pub fn new(name: &str, description: &str, mtime: &glib::DateTime, ctime: &glib::DateTime, size: usize, data: /*Unimplemented*/Option<Basic: Pointer>) -> Attachment {
    //    unsafe { TODO: call ffi:pps_attachment_new() }
    //}

    #[doc(alias = "pps_attachment_error_quark")]
    pub fn error_quark() -> glib::Quark {
        assert_initialized_main_thread!();
        unsafe { from_glib(ffi::pps_attachment_error_quark()) }
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Attachment>> Sealed for T {}
}

pub trait AttachmentExt: IsA<Attachment> + sealed::Sealed + 'static {
    #[doc(alias = "pps_attachment_get_creation_datetime")]
    #[doc(alias = "get_creation_datetime")]
    fn creation_datetime(&self) -> Option<glib::DateTime> {
        unsafe {
            from_glib_full(ffi::pps_attachment_get_creation_datetime(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "pps_attachment_get_description")]
    #[doc(alias = "get_description")]
    fn description(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::pps_attachment_get_description(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "pps_attachment_get_mime_type")]
    #[doc(alias = "get_mime_type")]
    fn mime_type(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::pps_attachment_get_mime_type(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "pps_attachment_get_modification_datetime")]
    #[doc(alias = "get_modification_datetime")]
    fn modification_datetime(&self) -> Option<glib::DateTime> {
        unsafe {
            from_glib_full(ffi::pps_attachment_get_modification_datetime(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "pps_attachment_get_name")]
    #[doc(alias = "get_name")]
    fn name(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::pps_attachment_get_name(self.as_ref().to_glib_none().0)) }
    }

    #[doc(alias = "pps_attachment_open")]
    fn open(&self, context: &impl IsA<gio::AppLaunchContext>) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::pps_attachment_open(
                self.as_ref().to_glib_none().0,
                context.as_ref().to_glib_none().0,
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[doc(alias = "pps_attachment_save")]
    fn save(&self, file: &impl IsA<gio::File>) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::pps_attachment_save(
                self.as_ref().to_glib_none().0,
                file.as_ref().to_glib_none().0,
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }
}

impl<O: IsA<Attachment>> AttachmentExt for O {}
