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

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

#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "RsvgError")]
pub enum Error {
    #[doc(alias = "RSVG_ERROR_FAILED")]
    Failed,
    #[doc(hidden)]
    __Unknown(i32),
}

#[doc(hidden)]
impl IntoGlib for Error {
    type GlibType = ffi::RsvgError;

    #[inline]
    fn into_glib(self) -> ffi::RsvgError {
        match self {
            Self::Failed => ffi::RSVG_ERROR_FAILED,
            Self::__Unknown(value) => value,
        }
    }
}

#[doc(hidden)]
impl FromGlib<ffi::RsvgError> for Error {
    #[inline]
    unsafe fn from_glib(value: ffi::RsvgError) -> Self {
        skip_assert_initialized!();

        match value {
            ffi::RSVG_ERROR_FAILED => Self::Failed,
            value => Self::__Unknown(value),
        }
    }
}

impl glib::error::ErrorDomain for Error {
    #[inline]
    fn domain() -> glib::Quark {
        skip_assert_initialized!();

        unsafe { from_glib(ffi::rsvg_error_quark()) }
    }

    #[inline]
    fn code(self) -> i32 {
        self.into_glib()
    }

    #[inline]
    #[allow(clippy::match_single_binding)]
    fn from(code: i32) -> Option<Self> {
        skip_assert_initialized!();
        match unsafe { from_glib(code) } {
            Self::__Unknown(_) => Some(Self::Failed),
            value => Some(value),
        }
    }
}

impl StaticType for Error {
    #[inline]
    #[doc(alias = "rsvg_error_get_type")]
    fn static_type() -> glib::Type {
        unsafe { from_glib(ffi::rsvg_error_get_type()) }
    }
}

impl glib::HasParamSpec for Error {
    type ParamSpec = glib::ParamSpecEnum;
    type SetValue = Self;
    type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>;

    fn param_spec_builder() -> Self::BuilderFn {
        Self::ParamSpec::builder_with_default
    }
}

impl glib::value::ValueType for Error {
    type Type = Self;
}

unsafe impl<'a> glib::value::FromValue<'a> for Error {
    type Checker = glib::value::GenericValueTypeChecker<Self>;

    #[inline]
    unsafe fn from_value(value: &'a glib::Value) -> Self {
        skip_assert_initialized!();
        from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
    }
}

impl ToValue for Error {
    #[inline]
    fn to_value(&self) -> glib::Value {
        let mut value = glib::Value::for_value_type::<Self>();
        unsafe {
            glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
        }
        value
    }

    #[inline]
    fn value_type(&self) -> glib::Type {
        Self::static_type()
    }
}

impl From<Error> for glib::Value {
    #[inline]
    fn from(v: Error) -> Self {
        skip_assert_initialized!();
        ToValue::to_value(&v)
    }
}

#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "RsvgUnit")]
pub enum Unit {
    #[doc(alias = "RSVG_UNIT_PERCENT")]
    Percent,
    #[doc(alias = "RSVG_UNIT_PX")]
    Px,
    #[doc(alias = "RSVG_UNIT_EM")]
    Em,
    #[doc(alias = "RSVG_UNIT_EX")]
    Ex,
    #[doc(alias = "RSVG_UNIT_IN")]
    In,
    #[doc(alias = "RSVG_UNIT_CM")]
    Cm,
    #[doc(alias = "RSVG_UNIT_MM")]
    Mm,
    #[doc(alias = "RSVG_UNIT_PT")]
    Pt,
    #[doc(alias = "RSVG_UNIT_PC")]
    Pc,
    #[cfg(feature = "v2_58")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v2_58")))]
    #[doc(alias = "RSVG_UNIT_CH")]
    Ch,
    #[doc(hidden)]
    __Unknown(i32),
}

#[doc(hidden)]
impl IntoGlib for Unit {
    type GlibType = ffi::RsvgUnit;

    #[inline]
    fn into_glib(self) -> ffi::RsvgUnit {
        match self {
            Self::Percent => ffi::RSVG_UNIT_PERCENT,
            Self::Px => ffi::RSVG_UNIT_PX,
            Self::Em => ffi::RSVG_UNIT_EM,
            Self::Ex => ffi::RSVG_UNIT_EX,
            Self::In => ffi::RSVG_UNIT_IN,
            Self::Cm => ffi::RSVG_UNIT_CM,
            Self::Mm => ffi::RSVG_UNIT_MM,
            Self::Pt => ffi::RSVG_UNIT_PT,
            Self::Pc => ffi::RSVG_UNIT_PC,
            #[cfg(feature = "v2_58")]
            Self::Ch => ffi::RSVG_UNIT_CH,
            Self::__Unknown(value) => value,
        }
    }
}

#[doc(hidden)]
impl FromGlib<ffi::RsvgUnit> for Unit {
    #[inline]
    unsafe fn from_glib(value: ffi::RsvgUnit) -> Self {
        skip_assert_initialized!();

        match value {
            ffi::RSVG_UNIT_PERCENT => Self::Percent,
            ffi::RSVG_UNIT_PX => Self::Px,
            ffi::RSVG_UNIT_EM => Self::Em,
            ffi::RSVG_UNIT_EX => Self::Ex,
            ffi::RSVG_UNIT_IN => Self::In,
            ffi::RSVG_UNIT_CM => Self::Cm,
            ffi::RSVG_UNIT_MM => Self::Mm,
            ffi::RSVG_UNIT_PT => Self::Pt,
            ffi::RSVG_UNIT_PC => Self::Pc,
            #[cfg(feature = "v2_58")]
            ffi::RSVG_UNIT_CH => Self::Ch,
            value => Self::__Unknown(value),
        }
    }
}
