// @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,
    clippy::zero_sized_map_values
)]

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

#[allow(non_camel_case_types)]
#[derive(
    Debug,
    Clone,
    Copy,
    Default,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Hash,
    serde::Serialize,
    serde::Deserialize,
)]
pub enum AttentionDelegatedAuthority {
    #[default]
    #[serde(rename = "AddEvidence")]
    AddEvidence,
    #[serde(rename = "CloseOwnReviewItem")]
    CloseOwnReviewItem,
    #[serde(rename = "RequestClosure")]
    RequestClosure,
    #[serde(rename = "CloseIfPolicyAllows")]
    CloseIfPolicyAllows,
}
impl AttentionDelegatedAuthority {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::AddEvidence => "AddEvidence",
            Self::CloseOwnReviewItem => "CloseOwnReviewItem",
            Self::RequestClosure => "RequestClosure",
            Self::CloseIfPolicyAllows => "CloseIfPolicyAllows",
        }
    }
}
impl std::convert::TryFrom<&str> for AttentionDelegatedAuthority {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "AddEvidence" => Ok(Self::AddEvidence),
            "CloseOwnReviewItem" => Ok(Self::CloseOwnReviewItem),
            "RequestClosure" => Ok(Self::RequestClosure),
            "CloseIfPolicyAllows" => Ok(Self::CloseIfPolicyAllows),
            other => Err(format!(
                "invalid AttentionDelegatedAuthority value `{other}`"
            )),
        }
    }
}
impl std::convert::TryFrom<String> for AttentionDelegatedAuthority {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for AttentionDelegatedAuthority {
    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 WorkAttentionBindingKey(pub String);
impl From<String> for WorkAttentionBindingKey {
    fn from(value: String) -> Self {
        Self(value)
    }
}
impl From<&str> for WorkAttentionBindingKey {
    fn from(value: &str) -> Self {
        Self(value.to_owned())
    }
}
impl std::fmt::Display for WorkAttentionBindingKey {
    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 WorkAttentionMode {
    #[default]
    #[serde(rename = "Pursue")]
    Pursue,
    #[serde(rename = "Coordinate")]
    Coordinate,
    #[serde(rename = "Review")]
    Review,
    #[serde(rename = "Falsify")]
    Falsify,
    #[serde(rename = "Judge")]
    Judge,
    #[serde(rename = "Observe")]
    Observe,
}
impl WorkAttentionMode {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Pursue => "Pursue",
            Self::Coordinate => "Coordinate",
            Self::Review => "Review",
            Self::Falsify => "Falsify",
            Self::Judge => "Judge",
            Self::Observe => "Observe",
        }
    }
}
impl std::convert::TryFrom<&str> for WorkAttentionMode {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "Pursue" => Ok(Self::Pursue),
            "Coordinate" => Ok(Self::Coordinate),
            "Review" => Ok(Self::Review),
            "Falsify" => Ok(Self::Falsify),
            "Judge" => Ok(Self::Judge),
            "Observe" => Ok(Self::Observe),
            other => Err(format!("invalid WorkAttentionMode value `{other}`")),
        }
    }
}
impl std::convert::TryFrom<String> for WorkAttentionMode {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for WorkAttentionMode {
    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,
    Superseded,
    Stopped,
}

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct State {
    pub phase: Phase,
    pub revision: u64,
    pub paused_until_utc_ms: Option<u64>,
    pub superseded_by_binding_key: Option<WorkAttentionBindingKey>,
    pub terminal_at_utc_ms: Option<u64>,
}
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 Pause {
        pub expected_revision: u64,
        pub until_utc_ms: Option<u64>,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct Resume {
        pub expected_revision: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct Supersede {
        pub expected_revision: u64,
        pub superseded_by_binding_key: WorkAttentionBindingKey,
        pub at_utc_ms: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct Stop {
        pub expected_revision: u64,
        pub at_utc_ms: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct ClassifyAttentionEligibility {
        pub now_utc_ms: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct ClassifyAttentionAuthority {
        pub mode: WorkAttentionMode,
        pub delegated_authority: AttentionDelegatedAuthority,
    }
}

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

pub mod effects {
    #[allow(unused_imports)]
    use super::*;
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct AttentionPaused {
        pub revision: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct AttentionResumed {
        pub revision: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct AttentionSuperseded {
        pub revision: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct AttentionStopped {
        pub revision: u64,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct AttentionEligibilityClassified {
        pub eligible: bool,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct AttentionAuthorityClassified {
        pub can_get: bool,
        pub can_add_evidence: bool,
        pub can_release: bool,
        pub can_update: bool,
        pub can_block: bool,
        pub can_create: bool,
        pub can_link: bool,
        pub can_link_parent: bool,
        pub can_link_related: bool,
        pub can_link_derived_from: bool,
        pub can_close_own_review_item: bool,
        pub can_close_if_policy_allows: bool,
    }
}

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum Effect {
    AttentionPaused(effects::AttentionPaused),
    AttentionResumed(effects::AttentionResumed),
    AttentionSuperseded(effects::AttentionSuperseded),
    AttentionStopped(effects::AttentionStopped),
    AttentionEligibilityClassified(effects::AttentionEligibilityClassified),
    AttentionAuthorityClassified(effects::AttentionAuthorityClassified),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum EffectKind {
    AttentionPaused,
    AttentionResumed,
    AttentionSuperseded,
    AttentionStopped,
    AttentionEligibilityClassified,
    AttentionAuthorityClassified,
}

#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum TransitionId {
    PauseActive,
    PausePaused,
    ResumePaused,
    SupersedeActive,
    SupersedePaused,
    StopActive,
    StopPaused,
    ClassifyEligibilityActive,
    ClassifyEligibilityPausedElapsed,
    ClassifyEligibilityPausedPending,
    ClassifyEligibilitySuperseded,
    ClassifyEligibilityStopped,
    ClassifyAuthorityActive,
    ClassifyAuthorityPaused,
    ClassifyAuthoritySuperseded,
    ClassifyAuthorityStopped,
}
#[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: 1,
        paused_until_utc_ms: None,
        superseded_by_binding_key: None,
        terminal_at_utc_ms: None,
    }
}
