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

use crate::{ffi,CountryInfo,MobileProvider};
use glib::{prelude::*,translate::*};
use std::{boxed::Box as Box_,pin::Pin};

#[cfg(feature = "gio_v2_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "gio_v2_22")))]
glib::wrapper! {
    ///
    ///
    /// ## Properties
    ///
    ///
    /// #### `country-codes`
    ///  Readable | Writeable | Construct Only
    ///
    ///
    /// #### `service-providers`
    ///  Readable | Writeable | Construct Only
    ///
    /// # Implements
    ///
    /// [`MobileProvidersDatabaseExt`][trait@crate::prelude::MobileProvidersDatabaseExt], [`trait@gio::prelude::AsyncInitableExt`], [`trait@gio::prelude::InitableExt`]
    #[doc(alias = "NMAMobileProvidersDatabase")]
    pub struct MobileProvidersDatabase(Object<ffi::NMAMobileProvidersDatabase, ffi::NMAMobileProvidersDatabaseClass>) @implements gio::AsyncInitable, gio::Initable;

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

#[cfg(not(any(feature = "gio_v2_22")))]
#[cfg(feature = "gio_v2_22")]
glib::wrapper! {
    #[doc(alias = "NMAMobileProvidersDatabase")]
    pub struct MobileProvidersDatabase(Object<ffi::NMAMobileProvidersDatabase, ffi::NMAMobileProvidersDatabaseClass>) @implements gio::Initable;

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

#[cfg(not(any(feature = "gio_v2_22")))]
glib::wrapper! {
    #[doc(alias = "NMAMobileProvidersDatabase")]
    pub struct MobileProvidersDatabase(Object<ffi::NMAMobileProvidersDatabase, ffi::NMAMobileProvidersDatabaseClass>);

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

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

    /// ## `country_codes`
    /// Path to the country codes file.
    /// ## `service_providers`
    /// Path to the service providers file.
    /// ## `cancellable`
    /// A #GCancellable or [`None`].
    ///
    /// # Returns
    ///
    /// The constructed object or [`None`] if @error is set.
    #[doc(alias = "nma_mobile_providers_database_new_sync")]
    pub fn new_sync(country_codes: Option<&str>, service_providers: Option<&str>, cancellable: Option<&impl IsA<gio::Cancellable>>) -> Result<MobileProvidersDatabase, glib::Error> {
        assert_initialized_main_thread!();
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::nma_mobile_providers_database_new_sync(country_codes.to_glib_none().0, service_providers.to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error);
            if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
        }
    }

            // rustdoc-stripper-ignore-next
            /// Creates a new builder-pattern struct instance to construct [`MobileProvidersDatabase`] objects.
            ///
            /// This method returns an instance of [`MobileProvidersDatabaseBuilder`](crate::builders::MobileProvidersDatabaseBuilder) which can be used to create [`MobileProvidersDatabase`] objects.
            pub fn builder() -> MobileProvidersDatabaseBuilder {
                MobileProvidersDatabaseBuilder::new()
            }
        

    /// ## `country_codes`
    /// Path to the country codes file.
    /// ## `service_providers`
    /// Path to the service providers file.
    /// ## `cancellable`
    /// A #GCancellable or [`None`].
    /// ## `callback`
    /// A #GAsyncReadyCallback to call when the request is satisfied.
    #[doc(alias = "nma_mobile_providers_database_new")]
    pub fn new<P: FnOnce(Result<MobileProvidersDatabase, glib::Error>) + 'static>(country_codes: Option<&str>, service_providers: Option<&str>, cancellable: Option<&impl IsA<gio::Cancellable>>, callback: P) {
        assert_initialized_main_thread!();
        
                let main_context = glib::MainContext::ref_thread_default();
                let is_main_context_owner = main_context.is_owner();
                let has_acquired_main_context = (!is_main_context_owner)
                    .then(|| main_context.acquire().ok())
                    .flatten();
                assert!(
                    is_main_context_owner || has_acquired_main_context.is_some(),
                    "Async operations only allowed if the thread is owning the MainContext"
                );
        
        let user_data: Box_<glib::thread_guard::ThreadGuard<P>> = Box_::new(glib::thread_guard::ThreadGuard::new(callback));
        unsafe extern "C" fn new_trampoline<P: FnOnce(Result<MobileProvidersDatabase, glib::Error>) + 'static>(_source_object: *mut glib::gobject_ffi::GObject, res: *mut gio::ffi::GAsyncResult, user_data: glib::ffi::gpointer) {
            let mut error = std::ptr::null_mut();
            let ret = ffi::nma_mobile_providers_database_new_finish(res, &mut error);
            let result = if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) };
            let callback: Box_<glib::thread_guard::ThreadGuard<P>> = Box_::from_raw(user_data as *mut _);
            let callback: P = callback.into_inner();
            callback(result);
        }
        let callback = new_trampoline::<P>;
        unsafe {
            ffi::nma_mobile_providers_database_new(country_codes.to_glib_none().0, service_providers.to_glib_none().0, cancellable.map(|p| p.as_ref()).to_glib_none().0, Some(callback), Box_::into_raw(user_data) as *mut _);
        }
    }

    
    pub fn new_future(country_codes: Option<&str>, service_providers: Option<&str>) -> Pin<Box_<dyn std::future::Future<Output = Result<MobileProvidersDatabase, glib::Error>> + 'static>> {

        skip_assert_initialized!();
        let country_codes = country_codes.map(ToOwned::to_owned);
        let service_providers = service_providers.map(ToOwned::to_owned);
        Box_::pin(gio::GioFuture::new(&(), move |_obj, cancellable, send| {
            Self::new(
                country_codes.as_ref().map(::std::borrow::Borrow::borrow),
                service_providers.as_ref().map(::std::borrow::Borrow::borrow),
                Some(cancellable),
                move |res| {
                    send.resolve(res);
                },
            );
        }))
    }
}

// rustdoc-stripper-ignore-next
        /// A [builder-pattern] type to construct [`MobileProvidersDatabase`] objects.
        ///
        /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct MobileProvidersDatabaseBuilder {
            builder: glib::object::ObjectBuilder<'static, MobileProvidersDatabase>,
        }

        impl MobileProvidersDatabaseBuilder {
        fn new() -> Self {
            Self { builder: glib::object::Object::builder() }
        }

                            pub fn country_codes(self, country_codes: impl Into<glib::GString>) -> Self {
                            Self { builder: self.builder.property("country-codes", country_codes.into()), }
                        }

                            pub fn service_providers(self, service_providers: impl Into<glib::GString>) -> Self {
                            Self { builder: self.builder.property("service-providers", service_providers.into()), }
                        }

    // rustdoc-stripper-ignore-next
    /// Build the [`MobileProvidersDatabase`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> MobileProvidersDatabase {
assert_initialized_main_thread!();
    self.builder.build() }
}

/// Trait containing all [`struct@MobileProvidersDatabase`] methods.
///
/// # Implementors
///
/// [`MobileProvidersDatabase`][struct@crate::MobileProvidersDatabase]
pub trait MobileProvidersDatabaseExt: IsA<MobileProvidersDatabase> + 'static {
    #[doc(alias = "nma_mobile_providers_database_dump")]
    fn dump(&self) {
        unsafe {
            ffi::nma_mobile_providers_database_dump(self.as_ref().to_glib_none().0);
        }
    }

    //#[doc(alias = "nma_mobile_providers_database_get_countries")]
    //#[doc(alias = "get_countries")]
    //fn countries(&self) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 1, id: 7 } {
    //    unsafe { TODO: call ffi:nma_mobile_providers_database_get_countries() }
    //}

    /// ## `mccmnc`
    /// the MCC/MNC string to look for.
    ///
    /// # Returns
    ///
    /// a #NMAMobileProvider or [`None`] if not found.
    #[doc(alias = "nma_mobile_providers_database_lookup_3gpp_mcc_mnc")]
    fn lookup_3gpp_mcc_mnc(&self, mccmnc: &str) -> MobileProvider {
        unsafe {
            from_glib_none(ffi::nma_mobile_providers_database_lookup_3gpp_mcc_mnc(self.as_ref().to_glib_none().0, mccmnc.to_glib_none().0))
        }
    }

    /// ## `sid`
    /// the SID to look for.
    ///
    /// # Returns
    ///
    /// a #NMAMobileProvider, or [`None`] if not found.
    #[doc(alias = "nma_mobile_providers_database_lookup_cdma_sid")]
    fn lookup_cdma_sid(&self, sid: u32) -> MobileProvider {
        unsafe {
            from_glib_none(ffi::nma_mobile_providers_database_lookup_cdma_sid(self.as_ref().to_glib_none().0, sid))
        }
    }

    /// ## `country_code`
    /// the country code string to look for.
    ///
    /// # Returns
    ///
    /// a #NMACountryInfo or [`None`] if not found.
    #[doc(alias = "nma_mobile_providers_database_lookup_country")]
    fn lookup_country(&self, country_code: &str) -> CountryInfo {
        unsafe {
            from_glib_none(ffi::nma_mobile_providers_database_lookup_country(self.as_ref().to_glib_none().0, country_code.to_glib_none().0))
        }
    }

    #[doc(alias = "country-codes")]
    fn country_codes(&self) -> Option<glib::GString> {
        ObjectExt::property(self.as_ref(), "country-codes")
    }

    #[doc(alias = "service-providers")]
    fn service_providers(&self) -> Option<glib::GString> {
        ObjectExt::property(self.as_ref(), "service-providers")
    }
}

impl<O: IsA<MobileProvidersDatabase>> MobileProvidersDatabaseExt for O {}
