#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct EventConditionParam {
pub param_id: Option<String>,
pub value: Option<String>,
pub param_type: Option<String>,
pub param_unit: Option<String>,
}
impl EventConditionParam {
pub fn new(param_id: impl Into<String>, value: impl Into<String>) -> Self {
Self {
param_id: Some(param_id.into()),
value: Some(value.into()),
param_type: None,
param_unit: None,
}
}
pub fn with_param_type(mut self, param_type: impl Into<String>) -> Self {
self.param_type = Some(param_type.into());
self
}
pub fn with_param_unit(mut self, param_unit: impl Into<String>) -> Self {
self.param_unit = Some(param_unit.into());
self
}
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct EventCondition {
pub subject_id: Option<String>,
pub model: Option<String>,
pub trigger_definition_id: String,
pub begin_time: Option<String>,
pub end_time: Option<String>,
pub params: Option<Vec<EventConditionParam>>,
}
impl EventCondition {
pub fn new(trigger_definition_id: impl Into<String>) -> Self {
Self {
subject_id: None,
model: None,
trigger_definition_id: trigger_definition_id.into(),
begin_time: None,
end_time: None,
params: None,
}
}
pub fn with_subject_id(mut self, subject_id: impl Into<String>) -> Self {
self.subject_id = Some(subject_id.into());
self
}
pub fn with_model(mut self, model: impl Into<String>) -> Self {
self.model = Some(model.into());
self
}
pub fn with_begin_time(mut self, begin_time: impl Into<String>) -> Self {
self.begin_time = Some(begin_time.into());
self
}
pub fn with_end_time(mut self, end_time: impl Into<String>) -> Self {
self.end_time = Some(end_time.into());
self
}
pub fn with_params(mut self, params: impl Into<Vec<EventConditionParam>>) -> Self {
self.params = Some(params.into());
self
}
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct CreateEventParams {
pub name: String,
pub position_id: Option<String>,
pub relation: i32,
pub condition: Vec<EventCondition>,
}
impl CreateEventParams {
pub fn new(
name: impl Into<String>,
relation: i32,
condition: impl Into<Vec<EventCondition>>,
) -> Self {
Self {
name: name.into(),
position_id: None,
relation,
condition: condition.into(),
}
}
pub fn with_position_id(mut self, position_id: impl Into<String>) -> Self {
self.position_id = Some(position_id.into());
self
}
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct UpdateEventParams {
pub event_id: String,
pub enable: i32,
pub name: String,
pub position_id: Option<String>,
pub relation: i32,
pub condition: Vec<EventCondition>,
}
impl UpdateEventParams {
pub fn new(
event_id: impl Into<String>,
enable: i32,
name: impl Into<String>,
relation: i32,
condition: impl Into<Vec<EventCondition>>,
) -> Self {
Self {
event_id: event_id.into(),
enable,
name: name.into(),
position_id: None,
relation,
condition: condition.into(),
}
}
pub fn with_position_id(mut self, position_id: impl Into<String>) -> Self {
self.position_id = Some(position_id.into());
self
}
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct DeleteEventParams {
pub event_id: String,
}
impl DeleteEventParams {
pub fn new(event_id: impl Into<String>) -> Self {
Self {
event_id: event_id.into(),
}
}
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct QueryEventDetailParams {
pub event_id: String,
}
impl QueryEventDetailParams {
pub fn new(event_id: impl Into<String>) -> Self {
Self {
event_id: event_id.into(),
}
}
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct QueryEventsBySubjectIdParams {
pub subject_id: String,
}
impl QueryEventsBySubjectIdParams {
pub fn new(subject_id: impl Into<String>) -> Self {
Self {
subject_id: subject_id.into(),
}
}
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct QueryEventsByPositionIdParams {
pub position_id: Option<String>,
pub page_num: u32,
pub page_size: u32,
}
impl Default for QueryEventsByPositionIdParams {
fn default() -> Self {
Self {
position_id: None,
page_num: 1,
page_size: 50,
}
}
}
impl QueryEventsByPositionIdParams {
pub fn with_position_id(mut self, position_id: impl Into<String>) -> Self {
self.position_id = Some(position_id.into());
self
}
pub fn with_page_num(mut self, page_num: u32) -> Self {
self.page_num = page_num;
self
}
pub fn with_page_size(mut self, page_size: u32) -> Self {
self.page_size = page_size;
self
}
}