use serde::{Deserialize, Serialize};
use uqa_core::{
memory::{Produced, ProductionControl},
ValueRetentionError,
};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateEnum {
pub name: String,
pub labels: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AlterEnum {
pub name: String,
pub action: AlterEnumAction,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AlterEnumAction {
AddValue {
label: String,
if_not_exists: bool,
neighbor: Option<EnumNeighbor>,
},
RenameValue {
old: String,
new: String,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EnumNeighbor {
pub label: String,
pub after: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EnumTypeReference {
pub schema: String,
pub name: String,
pub oid: u32,
pub array_oid: u32,
}
impl PartialEq for EnumTypeReference {
fn eq(&self, other: &Self) -> bool {
self.oid == other.oid
}
}
impl Eq for EnumTypeReference {}
impl EnumTypeReference {
pub fn clone_with_control(
&self,
control: &ProductionControl<'_>,
) -> Result<Produced<Self>, ValueRetentionError> {
let schema = control.copy_text(&self.schema)?;
let name = control.copy_text(&self.name)?;
let (schema, schema_memory) = schema.into_parts();
let (name, name_memory) = name.into_parts();
control.finish(
Self {
schema,
name,
oid: self.oid,
array_oid: self.array_oid,
},
control.combine(schema_memory, name_memory),
)
}
}