use yog_data::Schema;
use yog_data::with::Raw;
#[derive(Debug, Clone, PartialEq, Eq, Schema)]
pub struct Where {
pub scope: String,
pub instance: String,
}
#[derive(Debug, Clone, Schema)]
pub struct Read {
pub mod_id: String,
pub at: Where,
pub owner: String,
pub ty: String,
}
#[derive(Debug, Clone, Default, Schema)]
pub struct Record {
#[data(with = "Raw")]
pub bytes: Vec<u8>,
}
#[derive(Debug, Clone, Schema)]
pub struct Write {
pub mod_id: String,
pub at: Where,
pub owner: String,
pub ty: String,
#[data(with = "Raw")]
pub bytes: Vec<u8>,
}
#[derive(Debug, Clone, Schema)]
pub struct Remove {
pub mod_id: String,
pub at: Where,
pub owner: String,
pub ty: Option<String>,
}
#[derive(Debug, Clone, Schema)]
pub struct Owners {
pub mod_id: String,
pub at: Where,
}
#[derive(Debug, Clone, PartialEq, Eq, Schema)]
pub struct SyncedRow {
pub kind: String,
pub owner: String,
pub key: String,
#[data(with = "Raw")]
pub bytes: Vec<u8>,
}
#[must_use]
pub fn record_key(owner: &str, ty: &str) -> String {
if owner.is_empty() {
ty.to_owned()
} else {
format!("{owner}{}{ty}", yog_ids::sep::PATH)
}
}
#[must_use]
pub fn owner_prefix(owner: &str) -> String {
format!("{owner}{}", yog_ids::sep::PATH)
}