use super::action::{ActionPresentationSchema, ActionPresentationSpec};
use crate::definition::ActionRef;
use schemars::JsonSchema;
use serde::Serialize;
use std::collections::BTreeMap;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AccountIdentitySpec {
pub id: String,
pub title: String,
pub icon: String,
pub order: i32,
}
impl AccountIdentitySpec {
pub fn new(id: impl Into<String>, title: impl Into<String>, icon: impl Into<String>) -> Self {
Self {
id: id.into(),
title: title.into(),
icon: icon.into(),
order: 0,
}
}
#[must_use]
pub fn order(mut self, order: i32) -> Self {
self.order = order;
self
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ModulePresentationSpec {
pub identity: AccountIdentitySpec,
pub title: String,
pub description: String,
pub icon: String,
pub order: i32,
pub app_route: Option<String>,
pub primary_action: Option<ActionRef>,
pub action_presentations: BTreeMap<ActionRef, ActionPresentationSpec>,
}
impl ModulePresentationSpec {
pub fn new(
identity: AccountIdentitySpec,
title: impl Into<String>,
icon: impl Into<String>,
) -> Self {
Self {
identity,
title: title.into(),
description: String::new(),
icon: icon.into(),
order: 0,
app_route: None,
primary_action: None,
action_presentations: BTreeMap::new(),
}
}
#[must_use]
pub fn description(mut self, description: impl Into<String>) -> Self {
self.description = description.into();
self
}
#[must_use]
pub fn order(mut self, order: i32) -> Self {
self.order = order;
self
}
#[must_use]
pub fn app_route(mut self, route: impl Into<String>) -> Self {
self.app_route = Some(route.into());
self
}
#[must_use]
pub fn primary_action(mut self, action: ActionRef) -> Self {
self.primary_action = Some(action);
self
}
#[must_use]
pub fn present_action(
mut self,
action: ActionRef,
presentation: ActionPresentationSpec,
) -> Self {
self.action_presentations.insert(action, presentation);
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, JsonSchema)]
pub struct AccountIdentitySchema {
pub id: String,
pub title: String,
pub icon: String,
pub order: i32,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, JsonSchema)]
pub struct ModulePresentationSchema {
pub module_id: String,
pub identity: AccountIdentitySchema,
pub title: String,
pub description: String,
pub icon: String,
pub order: i32,
pub app_route: Option<String>,
pub primary_action: Option<String>,
pub actions: Vec<String>,
pub action_presentations: Vec<ActionPresentationSchema>,
pub views: Vec<String>,
}