use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::types::EntityType;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CherryPick {
pub source_branch_id: Uuid,
pub target_branch_id: Uuid,
pub entity_selections: Vec<EntitySelection>,
pub message: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct EntitySelection {
pub entity_type: EntityType,
pub entity_ids: Vec<String>,
pub fields: Option<Vec<String>>,
}
impl CherryPick {
pub fn all_of_type(source: Uuid, target: Uuid, entity_type: EntityType) -> Self {
Self {
source_branch_id: source,
target_branch_id: target,
entity_selections: vec![EntitySelection {
entity_type,
entity_ids: Vec::new(),
fields: None,
}],
message: None,
}
}
pub fn specific_entities(
source: Uuid,
target: Uuid,
entity_type: EntityType,
ids: Vec<String>,
) -> Self {
Self {
source_branch_id: source,
target_branch_id: target,
entity_selections: vec![EntitySelection {
entity_type,
entity_ids: ids,
fields: None,
}],
message: None,
}
}
pub fn specific_fields(mut self, fields: Vec<String>) -> Self {
if let Some(sel) = self.entity_selections.last_mut() {
sel.fields = Some(fields);
}
self
}
pub fn with_message(mut self, message: impl Into<String>) -> Self {
self.message = Some(message.into());
self
}
}