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

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

glib::wrapper! {
    #[doc(alias = "OstreeGpgVerifyResult")]
    pub struct GpgVerifyResult(Object<ffi::OstreeGpgVerifyResult>);

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

impl GpgVerifyResult {
    #[doc(alias = "ostree_gpg_verify_result_count_all")]
    pub fn count_all(&self) -> u32 {
        unsafe {
            ffi::ostree_gpg_verify_result_count_all(self.to_glib_none().0)
        }
    }

    #[doc(alias = "ostree_gpg_verify_result_count_valid")]
    pub fn count_valid(&self) -> u32 {
        unsafe {
            ffi::ostree_gpg_verify_result_count_valid(self.to_glib_none().0)
        }
    }

    //#[doc(alias = "ostree_gpg_verify_result_get")]
    //pub fn get(&self, signature_index: u32, attrs: /*Unimplemented*/&CArray TypeId { ns_id: 1, id: 21 }) -> glib::Variant {
    //    unsafe { TODO: call ffi:ostree_gpg_verify_result_get() }
    //}

    #[doc(alias = "ostree_gpg_verify_result_get_all")]
    #[doc(alias = "get_all")]
    pub fn all(&self, signature_index: u32) -> glib::Variant {
        unsafe {
            from_glib_none(ffi::ostree_gpg_verify_result_get_all(self.to_glib_none().0, signature_index))
        }
    }

    #[doc(alias = "ostree_gpg_verify_result_lookup")]
    pub fn lookup(&self, key_id: &str) -> Option<u32> {
        unsafe {
            let mut out_signature_index = std::mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::ostree_gpg_verify_result_lookup(self.to_glib_none().0, key_id.to_glib_none().0, out_signature_index.as_mut_ptr()));
            if ret { Some(out_signature_index.assume_init()) } else { None }
        }
    }

    #[cfg(feature = "v2016_6")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v2016_6")))]
    #[doc(alias = "ostree_gpg_verify_result_require_valid_signature")]
    pub fn require_valid_signature(&self) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::ostree_gpg_verify_result_require_valid_signature(self.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)) }
        }
    }
}
