//! # `DBus` interface proxy for: `com.canonical.dbusmenu`
//!
//! This code was generated by `zbus-xmlgen` `2.0.1` from `DBus` introspection data.
//! Source unknown (quoted as `org.cannonical.indicator.xml` in `stray` crate).
//!
//! You may prefer to adapt it, instead of using it verbatim.
//!
//! More information can be found in the
//! [Writing a client proxy](https://dbus.pages.freedesktop.org/zbus/client.html)
//! section of the zbus documentation.
//!

use std::collections::HashMap;

use zbus::proxy;
use zbus::zvariant::{OwnedValue, Value};

use serde::{Deserialize, Serialize};
use zbus::zvariant::Type;

#[derive(Deserialize, Serialize, Type, PartialEq, Debug)]
pub(crate) struct MenuLayout {
    pub id: u32,
    pub fields: SubMenuLayout,
}

#[derive(Deserialize, Serialize, Type, PartialEq, Debug)]
pub(crate) struct SubMenuLayout {
    pub id: i32,
    pub fields: HashMap<String, OwnedValue>,
    pub submenus: Vec<OwnedValue>,
}

#[allow(dead_code)]
type GroupProperties = Vec<(i32, HashMap<String, zbus::zvariant::OwnedValue>)>;

#[derive(Deserialize, Serialize, Type, Debug, Clone)]
pub struct PropertiesUpdate<'a> {
    #[serde(borrow)]
    pub(crate) updated: Vec<UpdatedProps<'a>>,
    pub(crate) removed: Vec<RemovedProps<'a>>,
}

#[derive(Deserialize, Serialize, Type, Debug, Clone)]
pub struct UpdatedProps<'a> {
    pub(crate) id: i32,
    #[serde(borrow)]
    pub(crate) fields: HashMap<&'a str, Value<'a>>,
}

#[derive(Deserialize, Serialize, Type, Debug, Clone)]
pub struct RemovedProps<'a> {
    pub(crate) id: i32,
    #[serde(borrow)]
    pub(crate) fields: Vec<&'a str>,
}

#[proxy(interface = "com.canonical.dbusmenu", assume_defaults = true)]
pub trait DBusMenu {
    fn about_to_show(&self, id: i32) -> zbus::Result<bool>;

    fn event(
        &self,
        id: i32,
        event_id: &str,
        data: &zbus::zvariant::Value<'_>,
        timestamp: u32,
    ) -> zbus::Result<()>;

    fn get_group_properties(
        &self,
        ids: &[i32],
        property_names: &[&str],
    ) -> zbus::Result<(u32, GroupProperties)>;

    fn get_layout(
        &self,
        parent_id: i32,
        recursion_depth: i32,
        property_names: &[&str],
    ) -> zbus::Result<MenuLayout>;

    fn get_property(&self, id: i32, name: &str) -> zbus::Result<zbus::zvariant::OwnedValue>;

    #[zbus(signal)]
    fn item_activation_requested(&self, id: i32, timestamp: u32) -> zbus::Result<()>;

    #[zbus(signal)]
    fn items_properties_updated(
        &self,
        updated_props: Vec<(i32, HashMap<&str, Value<'_>>)>,
        removed_props: Vec<(i32, Vec<&str>)>,
    ) -> zbus::Result<()>;

    #[zbus(signal)]
    fn layout_updated(&self, revision: u32, parent: i32) -> zbus::Result<()>;

    #[zbus(property)]
    fn status(&self) -> zbus::Result<String>;

    #[zbus(property)]
    fn version(&self) -> zbus::Result<u32>;
}
