deltalake_core/kernel/models/
mod.rsuse std::collections::HashMap;
use serde::{Deserialize, Serialize};
pub(crate) mod actions;
pub(crate) mod fields;
mod schema;
pub use actions::*;
pub use schema::*;
#[derive(Debug, Hash, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub enum ActionType {
    Add,
    Cdc,
    CommitInfo,
    DomainMetadata,
    Metadata,
    Protocol,
    Remove,
    Txn,
    CheckpointMetadata,
    Sidecar,
}
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[allow(missing_docs)]
pub enum Action {
    #[serde(rename = "metaData")]
    Metadata(Metadata),
    Protocol(Protocol),
    Add(Add),
    Remove(Remove),
    Cdc(AddCDCFile),
    Txn(Transaction),
    CommitInfo(CommitInfo),
    DomainMetadata(DomainMetadata),
}
impl Action {
    pub fn commit_info(info: HashMap<String, serde_json::Value>) -> Self {
        Self::CommitInfo(CommitInfo {
            info,
            ..Default::default()
        })
    }
}
impl From<Add> for Action {
    fn from(a: Add) -> Self {
        Self::Add(a)
    }
}
impl From<Remove> for Action {
    fn from(a: Remove) -> Self {
        Self::Remove(a)
    }
}
impl From<AddCDCFile> for Action {
    fn from(a: AddCDCFile) -> Self {
        Self::Cdc(a)
    }
}
impl From<Metadata> for Action {
    fn from(a: Metadata) -> Self {
        Self::Metadata(a)
    }
}
impl From<Protocol> for Action {
    fn from(a: Protocol) -> Self {
        Self::Protocol(a)
    }
}
impl From<Transaction> for Action {
    fn from(a: Transaction) -> Self {
        Self::Txn(a)
    }
}
impl From<CommitInfo> for Action {
    fn from(a: CommitInfo) -> Self {
        Self::CommitInfo(a)
    }
}
impl From<DomainMetadata> for Action {
    fn from(a: DomainMetadata) -> Self {
        Self::DomainMetadata(a)
    }
}
impl Action {
    pub fn action_type(&self) -> ActionType {
        match self {
            Self::Add(_) => ActionType::Add,
            Self::Remove(_) => ActionType::Remove,
            Self::Cdc(_) => ActionType::Cdc,
            Self::Metadata(_) => ActionType::Metadata,
            Self::Protocol(_) => ActionType::Protocol,
            Self::Txn(_) => ActionType::Txn,
            Self::CommitInfo(_) => ActionType::CommitInfo,
            Self::DomainMetadata(_) => ActionType::DomainMetadata,
        }
    }
}