// @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_session_turn_admission_machine()
}

#[allow(non_camel_case_types)]
#[derive(
    Debug,
    Clone,
    Copy,
    Default,
    PartialEq,
    Eq,
    PartialOrd,
    Ord,
    Hash,
    serde::Serialize,
    serde::Deserialize,
)]
pub enum PendingContinuationDisposition {
    #[default]
    #[serde(rename = "RunPending")]
    RunPending,
    #[serde(rename = "NoPendingBoundary")]
    NoPendingBoundary,
}
impl PendingContinuationDisposition {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::RunPending => "RunPending",
            Self::NoPendingBoundary => "NoPendingBoundary",
        }
    }
}
impl std::convert::TryFrom<&str> for PendingContinuationDisposition {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "RunPending" => Ok(Self::RunPending),
            "NoPendingBoundary" => Ok(Self::NoPendingBoundary),
            other => Err(format!(
                "invalid PendingContinuationDisposition value `{other}`"
            )),
        }
    }
}
impl std::convert::TryFrom<String> for PendingContinuationDisposition {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for PendingContinuationDisposition {
    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 RuntimeKeepAlivePersistenceDecision {
    #[default]
    #[serde(rename = "PersistEnabled")]
    PersistEnabled,
    #[serde(rename = "PersistDisabled")]
    PersistDisabled,
    #[serde(rename = "PreserveExisting")]
    PreserveExisting,
}
impl RuntimeKeepAlivePersistenceDecision {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::PersistEnabled => "PersistEnabled",
            Self::PersistDisabled => "PersistDisabled",
            Self::PreserveExisting => "PreserveExisting",
        }
    }
}
impl std::convert::TryFrom<&str> for RuntimeKeepAlivePersistenceDecision {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "PersistEnabled" => Ok(Self::PersistEnabled),
            "PersistDisabled" => Ok(Self::PersistDisabled),
            "PreserveExisting" => Ok(Self::PreserveExisting),
            other => Err(format!(
                "invalid RuntimeKeepAlivePersistenceDecision value `{other}`"
            )),
        }
    }
}
impl std::convert::TryFrom<String> for RuntimeKeepAlivePersistenceDecision {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for RuntimeKeepAlivePersistenceDecision {
    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 RuntimeKeepAliveRequest {
    #[default]
    #[serde(rename = "Enable")]
    Enable,
    #[serde(rename = "Disable")]
    Disable,
    #[serde(rename = "Preserve")]
    Preserve,
}
impl RuntimeKeepAliveRequest {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Enable => "Enable",
            Self::Disable => "Disable",
            Self::Preserve => "Preserve",
        }
    }
}
impl std::convert::TryFrom<&str> for RuntimeKeepAliveRequest {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "Enable" => Ok(Self::Enable),
            "Disable" => Ok(Self::Disable),
            "Preserve" => Ok(Self::Preserve),
            other => Err(format!("invalid RuntimeKeepAliveRequest value `{other}`")),
        }
    }
}
impl std::convert::TryFrom<String> for RuntimeKeepAliveRequest {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for RuntimeKeepAliveRequest {
    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 RuntimeSystemContextApplicationAuthorization {
    #[default]
    #[serde(rename = "Authorized")]
    Authorized,
    #[serde(rename = "SessionArchived")]
    SessionArchived,
}
impl RuntimeSystemContextApplicationAuthorization {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Authorized => "Authorized",
            Self::SessionArchived => "SessionArchived",
        }
    }
}
impl std::convert::TryFrom<&str> for RuntimeSystemContextApplicationAuthorization {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "Authorized" => Ok(Self::Authorized),
            "SessionArchived" => Ok(Self::SessionArchived),
            other => Err(format!(
                "invalid RuntimeSystemContextApplicationAuthorization value `{other}`"
            )),
        }
    }
}
impl std::convert::TryFrom<String> for RuntimeSystemContextApplicationAuthorization {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for RuntimeSystemContextApplicationAuthorization {
    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 StartTurnDispatchAuthorization {
    #[default]
    #[serde(rename = "Authorized")]
    Authorized,
    #[serde(rename = "Cancelled")]
    Cancelled,
}
impl StartTurnDispatchAuthorization {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Authorized => "Authorized",
            Self::Cancelled => "Cancelled",
        }
    }
}
impl std::convert::TryFrom<&str> for StartTurnDispatchAuthorization {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "Authorized" => Ok(Self::Authorized),
            "Cancelled" => Ok(Self::Cancelled),
            other => Err(format!(
                "invalid StartTurnDispatchAuthorization value `{other}`"
            )),
        }
    }
}
impl std::convert::TryFrom<String> for StartTurnDispatchAuthorization {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for StartTurnDispatchAuthorization {
    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 StartTurnDisposition {
    #[default]
    #[serde(rename = "RunContentTurn")]
    RunContentTurn,
    #[serde(rename = "RunPending")]
    RunPending,
    #[serde(rename = "NoPendingBoundary")]
    NoPendingBoundary,
}
impl StartTurnDisposition {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::RunContentTurn => "RunContentTurn",
            Self::RunPending => "RunPending",
            Self::NoPendingBoundary => "NoPendingBoundary",
        }
    }
}
impl std::convert::TryFrom<&str> for StartTurnDisposition {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "RunContentTurn" => Ok(Self::RunContentTurn),
            "RunPending" => Ok(Self::RunPending),
            "NoPendingBoundary" => Ok(Self::NoPendingBoundary),
            other => Err(format!("invalid StartTurnDisposition value `{other}`")),
        }
    }
}
impl std::convert::TryFrom<String> for StartTurnDisposition {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for StartTurnDisposition {
    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 StartTurnExecutionKind {
    #[default]
    #[serde(rename = "ContentTurn")]
    ContentTurn,
    #[serde(rename = "ResumePending")]
    ResumePending,
}
impl StartTurnExecutionKind {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::ContentTurn => "ContentTurn",
            Self::ResumePending => "ResumePending",
        }
    }
}
impl std::convert::TryFrom<&str> for StartTurnExecutionKind {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "ContentTurn" => Ok(Self::ContentTurn),
            "ResumePending" => Ok(Self::ResumePending),
            other => Err(format!("invalid StartTurnExecutionKind value `{other}`")),
        }
    }
}
impl std::convert::TryFrom<String> for StartTurnExecutionKind {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for StartTurnExecutionKind {
    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 StartTurnPublicTerminal {
    #[default]
    #[serde(rename = "NoPendingBoundary")]
    NoPendingBoundary,
}
impl StartTurnPublicTerminal {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::NoPendingBoundary => "NoPendingBoundary",
        }
    }
}
impl std::convert::TryFrom<&str> for StartTurnPublicTerminal {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "NoPendingBoundary" => Ok(Self::NoPendingBoundary),
            other => Err(format!("invalid StartTurnPublicTerminal value `{other}`")),
        }
    }
}
impl std::convert::TryFrom<String> for StartTurnPublicTerminal {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for StartTurnPublicTerminal {
    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 TurnAdmissionPhase {
    #[default]
    #[serde(rename = "Idle")]
    Idle,
    #[serde(rename = "Admitted")]
    Admitted,
    #[serde(rename = "Running")]
    Running,
    #[serde(rename = "Completing")]
    Completing,
    #[serde(rename = "ShuttingDown")]
    ShuttingDown,
}
impl TurnAdmissionPhase {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Idle => "Idle",
            Self::Admitted => "Admitted",
            Self::Running => "Running",
            Self::Completing => "Completing",
            Self::ShuttingDown => "ShuttingDown",
        }
    }
}
impl std::convert::TryFrom<&str> for TurnAdmissionPhase {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "Idle" => Ok(Self::Idle),
            "Admitted" => Ok(Self::Admitted),
            "Running" => Ok(Self::Running),
            "Completing" => Ok(Self::Completing),
            "ShuttingDown" => Ok(Self::ShuttingDown),
            other => Err(format!("invalid TurnAdmissionPhase value `{other}`")),
        }
    }
}
impl std::convert::TryFrom<String> for TurnAdmissionPhase {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for TurnAdmissionPhase {
    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 TurnAdmissionShutdownTerminal {
    #[default]
    #[serde(rename = "SessionArchived")]
    SessionArchived,
}
impl TurnAdmissionShutdownTerminal {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::SessionArchived => "SessionArchived",
        }
    }
}
impl std::convert::TryFrom<&str> for TurnAdmissionShutdownTerminal {
    type Error = String;
    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "SessionArchived" => Ok(Self::SessionArchived),
            other => Err(format!(
                "invalid TurnAdmissionShutdownTerminal value `{other}`"
            )),
        }
    }
}
impl std::convert::TryFrom<String> for TurnAdmissionShutdownTerminal {
    type Error = String;
    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(value.as_str())
    }
}
impl std::fmt::Display for TurnAdmissionShutdownTerminal {
    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 {
    Idle,
    Admitted,
    Running,
    Completing,
    ShuttingDown,
}

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct State {
    pub phase: Phase,
    pub interrupt_pending: bool,
    pub shutdown_pending: bool,
    pub admission_drain_pending: bool,
    pub last_public_terminal: Option<StartTurnPublicTerminal>,
}
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 ProjectTurnAdmission {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct ClaimTurn {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct AbortClaim {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct BeginTurn {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct ResolveTurn {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct FinalizeTurn {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct RequestInterrupt {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct RequestShutdown {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct AuthorizeStartTurnDispatch {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct AuthorizeCancelAfterBoundary {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct ResolveLastStartTurnPublicTerminal {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct AuthorizeRuntimeSystemContextApplication {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct ResolvePendingAdmissionDrained {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct AuthorizeSessionTeardown {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct ResolveRuntimeKeepAlive {
        pub keep_alive_request: RuntimeKeepAliveRequest,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct ResolveStartTurnDisposition {
        pub execution_kind_present: bool,
        pub execution_kind: StartTurnExecutionKind,
        pub prompt_trimmed_text_byte_count: u64,
        pub prompt_non_text_block_count: u64,
        pub pending_continuation: PendingContinuationDisposition,
    }
}

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum Input {
    ProjectTurnAdmission(inputs::ProjectTurnAdmission),
    ClaimTurn(inputs::ClaimTurn),
    AbortClaim(inputs::AbortClaim),
    BeginTurn(inputs::BeginTurn),
    ResolveTurn(inputs::ResolveTurn),
    FinalizeTurn(inputs::FinalizeTurn),
    RequestInterrupt(inputs::RequestInterrupt),
    RequestShutdown(inputs::RequestShutdown),
    AuthorizeStartTurnDispatch(inputs::AuthorizeStartTurnDispatch),
    AuthorizeCancelAfterBoundary(inputs::AuthorizeCancelAfterBoundary),
    ResolveLastStartTurnPublicTerminal(inputs::ResolveLastStartTurnPublicTerminal),
    AuthorizeRuntimeSystemContextApplication(inputs::AuthorizeRuntimeSystemContextApplication),
    ResolvePendingAdmissionDrained(inputs::ResolvePendingAdmissionDrained),
    AuthorizeSessionTeardown(inputs::AuthorizeSessionTeardown),
    ResolveRuntimeKeepAlive(inputs::ResolveRuntimeKeepAlive),
    ResolveStartTurnDisposition(inputs::ResolveStartTurnDisposition),
}
impl Input {
    pub fn kind(&self) -> InputKind {
        match self {
            Self::ProjectTurnAdmission(_) => InputKind::ProjectTurnAdmission,
            Self::ClaimTurn(_) => InputKind::ClaimTurn,
            Self::AbortClaim(_) => InputKind::AbortClaim,
            Self::BeginTurn(_) => InputKind::BeginTurn,
            Self::ResolveTurn(_) => InputKind::ResolveTurn,
            Self::FinalizeTurn(_) => InputKind::FinalizeTurn,
            Self::RequestInterrupt(_) => InputKind::RequestInterrupt,
            Self::RequestShutdown(_) => InputKind::RequestShutdown,
            Self::AuthorizeStartTurnDispatch(_) => InputKind::AuthorizeStartTurnDispatch,
            Self::AuthorizeCancelAfterBoundary(_) => InputKind::AuthorizeCancelAfterBoundary,
            Self::ResolveLastStartTurnPublicTerminal(_) => {
                InputKind::ResolveLastStartTurnPublicTerminal
            }
            Self::AuthorizeRuntimeSystemContextApplication(_) => {
                InputKind::AuthorizeRuntimeSystemContextApplication
            }
            Self::ResolvePendingAdmissionDrained(_) => InputKind::ResolvePendingAdmissionDrained,
            Self::AuthorizeSessionTeardown(_) => InputKind::AuthorizeSessionTeardown,
            Self::ResolveRuntimeKeepAlive(_) => InputKind::ResolveRuntimeKeepAlive,
            Self::ResolveStartTurnDisposition(_) => InputKind::ResolveStartTurnDisposition,
        }
    }
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum InputKind {
    ProjectTurnAdmission,
    ClaimTurn,
    AbortClaim,
    BeginTurn,
    ResolveTurn,
    FinalizeTurn,
    RequestInterrupt,
    RequestShutdown,
    AuthorizeStartTurnDispatch,
    AuthorizeCancelAfterBoundary,
    ResolveLastStartTurnPublicTerminal,
    AuthorizeRuntimeSystemContextApplication,
    ResolvePendingAdmissionDrained,
    AuthorizeSessionTeardown,
    ResolveRuntimeKeepAlive,
    ResolveStartTurnDisposition,
}

pub mod effects {
    #[allow(unused_imports)]
    use super::*;
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct TurnAdmissionProjected {
        pub phase: TurnAdmissionPhase,
        pub interrupt_pending: bool,
        pub shutdown_pending: bool,
        pub is_active: bool,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct TurnInterruptRequested {
        pub wake: bool,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct StartTurnDispatchResolved {
        pub authorization: StartTurnDispatchAuthorization,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct CancelAfterBoundaryAuthorized {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct StartTurnDispositionResolved {
        pub disposition: StartTurnDisposition,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct StartTurnPublicTerminalResolved {
        pub terminal: StartTurnPublicTerminal,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct RuntimeKeepAliveResolved {
        pub decision: RuntimeKeepAlivePersistenceDecision,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct PendingAdmissionDrainRequested {}
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct RuntimeSystemContextApplicationResolved {
        pub authorization: RuntimeSystemContextApplicationAuthorization,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct TurnAdmissionShutdownTerminalResolved {
        pub terminal: TurnAdmissionShutdownTerminal,
    }
    #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
    pub struct SessionTeardownAuthorized {}
}

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum Effect {
    TurnAdmissionProjected(effects::TurnAdmissionProjected),
    TurnInterruptRequested(effects::TurnInterruptRequested),
    StartTurnDispatchResolved(effects::StartTurnDispatchResolved),
    CancelAfterBoundaryAuthorized(effects::CancelAfterBoundaryAuthorized),
    StartTurnDispositionResolved(effects::StartTurnDispositionResolved),
    StartTurnPublicTerminalResolved(effects::StartTurnPublicTerminalResolved),
    RuntimeKeepAliveResolved(effects::RuntimeKeepAliveResolved),
    PendingAdmissionDrainRequested(effects::PendingAdmissionDrainRequested),
    RuntimeSystemContextApplicationResolved(effects::RuntimeSystemContextApplicationResolved),
    TurnAdmissionShutdownTerminalResolved(effects::TurnAdmissionShutdownTerminalResolved),
    SessionTeardownAuthorized(effects::SessionTeardownAuthorized),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum EffectKind {
    TurnAdmissionProjected,
    TurnInterruptRequested,
    StartTurnDispatchResolved,
    CancelAfterBoundaryAuthorized,
    StartTurnDispositionResolved,
    StartTurnPublicTerminalResolved,
    RuntimeKeepAliveResolved,
    PendingAdmissionDrainRequested,
    RuntimeSystemContextApplicationResolved,
    TurnAdmissionShutdownTerminalResolved,
    SessionTeardownAuthorized,
}

#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum TransitionId {
    ProjectTurnAdmissionIdle,
    ProjectTurnAdmissionAdmitted,
    ProjectTurnAdmissionRunning,
    ProjectTurnAdmissionCompleting,
    ProjectTurnAdmissionShuttingDown,
    ClaimTurn,
    AbortClaim,
    ClaimTurnShuttingDown,
    AbortClaimShuttingDown,
    BeginTurn,
    BeginTurnShuttingDown,
    ResolveTurn,
    FinalizeTurnToShutdown,
    FinalizeTurnToIdle,
    RequestInterruptAdmittedFirst,
    RequestInterruptAdmittedDuplicate,
    RequestInterruptRunningFirst,
    RequestInterruptRunningDuplicate,
    RequestShutdownImmediateIdle,
    RequestShutdownImmediateAdmitted,
    RequestShutdownDeferredRunning,
    RequestShutdownDeferredCompleting,
    RequestShutdownAlreadyShuttingDown,
    ResolvePendingAdmissionDrained,
    AuthorizeSessionTeardown,
    AuthorizeCancelAfterBoundaryAdmitted,
    AuthorizeStartTurnDispatchAdmitted,
    AuthorizeStartTurnDispatchShuttingDown,
    AuthorizeRuntimeSystemContextApplicationActiveIdle,
    AuthorizeRuntimeSystemContextApplicationActiveAdmitted,
    AuthorizeRuntimeSystemContextApplicationActiveRunning,
    AuthorizeRuntimeSystemContextApplicationActiveCompleting,
    AuthorizeRuntimeSystemContextApplicationShuttingDown,
    AuthorizeCancelAfterBoundaryRunning,
    ResolveDispositionContentTurn,
    ResolveDispositionResumePendingWithBoundary,
    ResolveDispositionResumePendingWithoutBoundary,
    ResolveDispositionDirectPrompt,
    ResolveDispositionDirectPending,
    ResolveDispositionDirectNoPending,
    ResolveStartTurnDispositionShuttingDown,
    ResolveRuntimeKeepAliveEnable,
    ResolveRuntimeKeepAliveDisable,
    ResolveRuntimeKeepAlivePreserve,
    ResolveRuntimeKeepAliveShuttingDown,
    ResolveLastStartTurnPublicTerminalNoPendingIdle,
    ResolveLastStartTurnPublicTerminalNoPendingAdmitted,
    ResolveLastStartTurnPublicTerminalNoPendingRunning,
    ResolveLastStartTurnPublicTerminalNoPendingCompleting,
    ResolveLastStartTurnPublicTerminalNoPendingShuttingDown,
}
#[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::Idle,
        interrupt_pending: false,
        shutdown_pending: false,
        admission_drain_pending: false,
        last_public_terminal: None,
    }
}
