// @generated — Generated by `cargo xtask machine-codegen --all`.
#![allow(
    clippy::unwrap_used,
    clippy::expect_used,
    clippy::panic,
    clippy::implicit_clone,
    clippy::unnecessary_cast,
    clippy::redundant_clone
)]

pub fn schema() -> meerkat_machine_schema::MachineSchema {
    meerkat_machine_schema::catalog::dsl::dsl_schedule_lifecycle_machine()
}

#[allow(non_camel_case_types)]
#[derive(
    Debug,
    Clone,
    Copy,
    Default,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Hash,
    serde::Serialize,
    serde::Deserialize,
)]
pub enum MisfirePolicy {
    #[default]
    #[serde(rename = "Skip")]
    Skip,
    #[serde(rename = "CatchUpWithin")]
    CatchUpWithin,
}
impl MisfirePolicy {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Skip => "Skip",
            Self::CatchUpWithin => "CatchUpWithin",
        }
    }
}
impl std::convert::TryFrom<&str> for MisfirePolicy {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "Skip" => Ok(Self::Skip),
            "CatchUpWithin" => Ok(Self::CatchUpWithin),
            other => Err(format!("invalid MisfirePolicy value `{other}`")),
        }
    }
}
impl std::convert::TryFrom<String> for MisfirePolicy {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for MisfirePolicy {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}
#[allow(non_camel_case_types)]
#[derive(
    Debug,
    Clone,
    Copy,
    Default,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Hash,
    serde::Serialize,
    serde::Deserialize,
)]
pub enum MissingTargetPolicy {
    #[default]
    #[serde(rename = "MarkMisfired")]
    MarkMisfired,
    #[serde(rename = "Skip")]
    Skip,
}
impl MissingTargetPolicy {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::MarkMisfired => "MarkMisfired",
            Self::Skip => "Skip",
        }
    }
}
impl std::convert::TryFrom<&str> for MissingTargetPolicy {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "MarkMisfired" => Ok(Self::MarkMisfired),
            "Skip" => Ok(Self::Skip),
            other => Err(format!("invalid MissingTargetPolicy value `{other}`")),
        }
    }
}
impl std::convert::TryFrom<String> for MissingTargetPolicy {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for MissingTargetPolicy {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}
#[derive(
    Debug,
    Clone,
    Default,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Hash,
    serde::Serialize,
    serde::Deserialize,
)]
pub struct OccurrenceId(pub String);
impl From<String> for OccurrenceId {
    fn from(value: String) -> Self {
        Self(value)
    }
}
impl From<&str> for OccurrenceId {
    fn from(value: &str) -> Self {
        Self(value.to_owned())
    }
}
impl std::fmt::Display for OccurrenceId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(&self.0)
    }
}
#[allow(non_camel_case_types)]
#[derive(
    Debug,
    Clone,
    Copy,
    Default,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Hash,
    serde::Serialize,
    serde::Deserialize,
)]
pub enum OverlapPolicy {
    #[default]
    #[serde(rename = "AllowConcurrent")]
    AllowConcurrent,
    #[serde(rename = "SkipIfRunning")]
    SkipIfRunning,
}
impl OverlapPolicy {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::AllowConcurrent => "AllowConcurrent",
            Self::SkipIfRunning => "SkipIfRunning",
        }
    }
}
impl std::convert::TryFrom<&str> for OverlapPolicy {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "AllowConcurrent" => Ok(Self::AllowConcurrent),
            "SkipIfRunning" => Ok(Self::SkipIfRunning),
            other => Err(format!("invalid OverlapPolicy value `{other}`")),
        }
    }
}
impl std::convert::TryFrom<String> for OverlapPolicy {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for OverlapPolicy {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}
#[allow(non_camel_case_types)]
#[derive(
    Debug,
    Clone,
    Copy,
    Default,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Hash,
    serde::Serialize,
    serde::Deserialize,
)]
pub enum ScheduleLifecycleState {
    #[default]
    #[serde(rename = "Active")]
    Active,
    #[serde(rename = "Paused")]
    Paused,
    #[serde(rename = "Deleted")]
    Deleted,
}
impl ScheduleLifecycleState {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Active => "Active",
            Self::Paused => "Paused",
            Self::Deleted => "Deleted",
        }
    }
}
impl std::convert::TryFrom<&str> for ScheduleLifecycleState {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "Active" => Ok(Self::Active),
            "Paused" => Ok(Self::Paused),
            "Deleted" => Ok(Self::Deleted),
            other => Err(format!("invalid ScheduleLifecycleState value `{other}`")),
        }
    }
}
impl std::convert::TryFrom<String> for ScheduleLifecycleState {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for ScheduleLifecycleState {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

pub trait Context {}
pub struct EmptyContext;
impl Context for EmptyContext {}

#[allow(non_camel_case_types)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum Phase {
    Active,
    Paused,
    Deleted,
}

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct State {
    pub phase: Phase,
    pub revision: u64,
    pub trigger_key: String,
    pub target_binding_key: String,
    pub misfire_policy: MisfirePolicy,
    pub overlap_policy: OverlapPolicy,
    pub missing_target_policy: MissingTargetPolicy,
    pub planning_cursor_utc_ms: Option<u64>,
    pub next_occurrence_ordinal: u64,
    pub superseded_ack_ids: std::collections::BTreeSet<OccurrenceId>,
}
impl Default for State {
    fn default() -> Self {
        initial_state()
    }
}

pub mod inputs {
    #[allow(unused_imports)]
    use super::*;
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct Create {
        pub trigger_key: String,
        pub target_binding_key: String,
        pub misfire_policy: MisfirePolicy,
        pub overlap_policy: OverlapPolicy,
        pub missing_target_policy: MissingTargetPolicy,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct Revise {
        pub trigger_key: String,
        pub target_binding_key: String,
        pub misfire_policy: MisfirePolicy,
        pub overlap_policy: OverlapPolicy,
        pub missing_target_policy: MissingTargetPolicy,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct RecordPlanningWindow {
        pub planning_cursor_utc_ms: u64,
        pub next_occurrence_ordinal: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct Pause {
        pub at_utc_ms: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct Resume {
        pub at_utc_ms: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct Delete {
        pub at_utc_ms: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct ConfirmOccurrencesSuperseded {
        pub occurrence_id: OccurrenceId,
        pub superseding_revision: u64,
    }
}

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum Input {
    Create(inputs::Create),
    Revise(inputs::Revise),
    RecordPlanningWindow(inputs::RecordPlanningWindow),
    Pause(inputs::Pause),
    Resume(inputs::Resume),
    Delete(inputs::Delete),
    ConfirmOccurrencesSuperseded(inputs::ConfirmOccurrencesSuperseded),
}
impl Input {
    pub fn kind(&self) -> InputKind {
        match self {
            Self::Create(_) => InputKind::Create,
            Self::Revise(_) => InputKind::Revise,
            Self::RecordPlanningWindow(_) => InputKind::RecordPlanningWindow,
            Self::Pause(_) => InputKind::Pause,
            Self::Resume(_) => InputKind::Resume,
            Self::Delete(_) => InputKind::Delete,
            Self::ConfirmOccurrencesSuperseded(_) => InputKind::ConfirmOccurrencesSuperseded,
        }
    }
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum InputKind {
    Create,
    Revise,
    RecordPlanningWindow,
    Pause,
    Resume,
    Delete,
    ConfirmOccurrencesSuperseded,
}

pub mod effects {
    #[allow(unused_imports)]
    use super::*;
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct EmitScheduleNotice {
        pub new_state: ScheduleLifecycleState,
        pub revision: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct SupersedePendingOccurrences {
        pub superseding_revision: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct PlanningWindowRecorded {
        pub planning_cursor_utc_ms: u64,
        pub next_occurrence_ordinal: u64,
    }
}

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum Effect {
    EmitScheduleNotice(effects::EmitScheduleNotice),
    SupersedePendingOccurrences(effects::SupersedePendingOccurrences),
    PlanningWindowRecorded(effects::PlanningWindowRecorded),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum EffectKind {
    EmitScheduleNotice,
    SupersedePendingOccurrences,
    PlanningWindowRecorded,
}

#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum TransitionId {
    CreateSchedule,
    ReviseActive,
    RevisePaused,
    RecordPlanningWindowActive,
    PauseActiveOrPaused,
    ResumeActiveOrPaused,
    DeleteActive,
    DeletePaused,
    DeleteDeleted,
    ConfirmOccurrencesSupersededActive,
    ConfirmOccurrencesSupersededPaused,
    ConfirmOccurrencesSupersededDeleted,
}
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum GuardId {
    None,
}
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum HelperId {
    None,
}

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct GuardRejection {
    pub transition_id: TransitionId,
    pub guard_id: GuardId,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum TriggerDiscriminant {
    Input(InputKind),
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum TransitionRefusal {
    NoMatchingTransition {
        phase: Phase,
        trigger: TriggerDiscriminant,
    },
    GuardRejected {
        rejections: Vec<GuardRejection>,
    },
    AmbiguousTransition {
        transitions: Vec<TransitionId>,
    },
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum KernelError {
    ContextViolation {
        transition_id: TransitionId,
        detail: String,
    },
    HelperEvaluation {
        helper_id: HelperId,
        detail: String,
    },
    CodegenInvariant {
        detail: String,
    },
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum TransitionError {
    Refusal(TransitionRefusal),
    Kernel(KernelError),
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct Outcome {
    pub transition_id: TransitionId,
    pub next_state: State,
    pub effects: Vec<Effect>,
}

pub mod helpers {
    #[allow(unused_imports)]
    use super::*;
    pub fn none<C: Context>(_: &State, context: &C) -> Result<(), KernelError> {
        let _ = context;
        Ok(())
    }
}

pub fn initial_state() -> State {
    State {
        phase: Phase::Active,
        revision: 0,
        trigger_key: String::new(),
        target_binding_key: String::new(),
        misfire_policy: MisfirePolicy::default(),
        overlap_policy: OverlapPolicy::default(),
        missing_target_policy: MissingTargetPolicy::default(),
        planning_cursor_utc_ms: None,
        next_occurrence_ordinal: 0,
        superseded_ack_ids: Default::default(),
    }
}
