use paste::paste;
use serde::Deserialize;

macro_rules! actions {
    ($($name:ident;)*) => {
        paste! {
            $(
                mod [<$name:snake>];
                pub use [<$name:snake>]::[<Config $name>];
            )*

            #[derive(Deserialize, Debug)]
            #[serde(tag = "$type")]
            pub enum ActionConfig {
                $(
                    $name([<Config $name>]),
                )*
            }

            impl ActionConfig {
                pub fn to_protocol(&self) -> ::proto::ActionInfo {
                    use ::prost::Message;

                    match self {
                        $(
                            Self::$name(config) => ::proto::ActionInfo {
                                body: config.to_protocol().encode_to_vec(),
                                action_type: ::proto::ActionType::$name.into(),
                                ..Default::default()
                            },
                        )*
                    }
                }
            }
        }
    };
}

actions! {
    SwitchSection;
    OpenUi;
}
