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

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

glib::wrapper! {
    #[doc(alias = "GUnixCredentialsMessage")]
    pub struct UnixCredentialsMessage(Object<ffi::GUnixCredentialsMessage, ffi::GUnixCredentialsMessageClass>) @extends SocketControlMessage;

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

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

    #[doc(alias = "g_unix_credentials_message_new")]
    pub fn new() -> UnixCredentialsMessage {
        unsafe {
            SocketControlMessage::from_glib_full(ffi::g_unix_credentials_message_new())
                .unsafe_cast()
        }
    }

    #[doc(alias = "g_unix_credentials_message_new_with_credentials")]
    #[doc(alias = "new_with_credentials")]
    pub fn with_credentials(credentials: &Credentials) -> UnixCredentialsMessage {
        unsafe {
            SocketControlMessage::from_glib_full(
                ffi::g_unix_credentials_message_new_with_credentials(credentials.to_glib_none().0),
            )
            .unsafe_cast()
        }
    }

    #[doc(alias = "g_unix_credentials_message_is_supported")]
    pub fn is_supported() -> bool {
        unsafe { from_glib(ffi::g_unix_credentials_message_is_supported()) }
    }
}

impl Default for UnixCredentialsMessage {
    fn default() -> Self {
        Self::new()
    }
}

pub trait UnixCredentialsMessageExt: IsA<UnixCredentialsMessage> + 'static {
    #[doc(alias = "g_unix_credentials_message_get_credentials")]
    #[doc(alias = "get_credentials")]
    fn credentials(&self) -> Credentials {
        unsafe {
            from_glib_none(ffi::g_unix_credentials_message_get_credentials(
                self.as_ref().to_glib_none().0,
            ))
        }
    }
}

impl<O: IsA<UnixCredentialsMessage>> UnixCredentialsMessageExt for O {}
