// 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::{Credentials, SocketControlMessage};
use glib::{prelude::*, translate::*};
use std::fmt;

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: 'static {
    #[doc(alias = "g_unix_credentials_message_get_credentials")]
    #[doc(alias = "get_credentials")]
    fn credentials(&self) -> Credentials;
}

impl<O: IsA<UnixCredentialsMessage>> UnixCredentialsMessageExt for O {
    fn credentials(&self) -> Credentials {
        unsafe {
            from_glib_none(ffi::g_unix_credentials_message_get_credentials(
                self.as_ref().to_glib_none().0,
            ))
        }
    }
}

impl fmt::Display for UnixCredentialsMessage {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("UnixCredentialsMessage")
    }
}
