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

use crate::{BreakpointConditionLengthType, BreakpointConditionRatioType, LengthUnit, ffi};
use glib::translate::*;

glib::wrapper! {
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct BreakpointCondition(Boxed<ffi::AdwBreakpointCondition>);

    match fn {
        copy => |ptr| ffi::adw_breakpoint_condition_copy(mut_override(ptr)),
        free => |ptr| ffi::adw_breakpoint_condition_free(ptr),
        type_ => || ffi::adw_breakpoint_condition_get_type(),
    }
}

impl BreakpointCondition {
    #[doc(alias = "adw_breakpoint_condition_new_and")]
    pub fn new_and(
        condition_1: BreakpointCondition,
        condition_2: BreakpointCondition,
    ) -> BreakpointCondition {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::adw_breakpoint_condition_new_and(
                condition_1.into_glib_ptr(),
                condition_2.into_glib_ptr(),
            ))
        }
    }

    #[doc(alias = "adw_breakpoint_condition_new_length")]
    pub fn new_length(
        type_: BreakpointConditionLengthType,
        value: f64,
        unit: LengthUnit,
    ) -> BreakpointCondition {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::adw_breakpoint_condition_new_length(
                type_.into_glib(),
                value,
                unit.into_glib(),
            ))
        }
    }

    #[doc(alias = "adw_breakpoint_condition_new_or")]
    pub fn new_or(
        condition_1: BreakpointCondition,
        condition_2: BreakpointCondition,
    ) -> BreakpointCondition {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::adw_breakpoint_condition_new_or(
                condition_1.into_glib_ptr(),
                condition_2.into_glib_ptr(),
            ))
        }
    }

    #[doc(alias = "adw_breakpoint_condition_new_ratio")]
    pub fn new_ratio(
        type_: BreakpointConditionRatioType,
        width: i32,
        height: i32,
    ) -> BreakpointCondition {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::adw_breakpoint_condition_new_ratio(
                type_.into_glib(),
                width,
                height,
            ))
        }
    }

    #[doc(alias = "adw_breakpoint_condition_to_string")]
    #[doc(alias = "to_string")]
    pub fn to_str(&self) -> glib::GString {
        unsafe {
            from_glib_full(ffi::adw_breakpoint_condition_to_string(mut_override(
                self.to_glib_none().0,
            )))
        }
    }

    #[doc(alias = "adw_breakpoint_condition_parse")]
    pub fn parse(str: &str) -> Result<BreakpointCondition, glib::BoolError> {
        assert_initialized_main_thread!();
        unsafe {
            Option::<_>::from_glib_full(ffi::adw_breakpoint_condition_parse(str.to_glib_none().0))
                .ok_or_else(|| glib::bool_error!("Invalid condition"))
        }
    }
}

impl std::fmt::Display for BreakpointCondition {
    #[inline]
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.write_str(&self.to_str())
    }
}
