ac-algorithm 0.2.0

Algorithm competition domain logic for ac
Documentation
//! Submissions: the intent/result state machine that prevents duplicate and
//! mismatched sends (C-07, ADR-0005 invariant 4).
//!
//! States follow `atcoder-integrated-environment-plan.md` §11: send intent,
//! in-flight, unknown outcome, judge acceptance, judging, finalized, failed.
//! A `ResultUnknown` submission is reconciled against official history — it
//! is never resent unconditionally. Transition enforcement and the actual
//! send pipeline are owned by issue #21.

use std::time::SystemTime;

use serde::{Deserialize, Serialize};

use crate::ids::{SolutionId, SubmissionId, TaskId};
use crate::verdict::JudgeVerdict;

/// Lifecycle of a [`Submission`].
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SubmissionState {
    /// Byte string fixed and send intended, not yet transmitted.
    Intent,
    /// Transmission in progress.
    Transmitting,
    /// The send outcome is unknown (e.g. connection lost mid-request).
    /// Reconcile with official history before any resend.
    ResultUnknown,
    /// The judge accepted the submission.
    Accepted,
    /// The judge is evaluating it.
    Judging,
    /// A final verdict was received.
    Completed,
    /// The submission failed before or during judging.
    Failed,
}

/// A submission record binding intent, fixed bytes, and official result.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Submission {
    /// Submission identifier.
    pub id: SubmissionId,
    /// Task the submission targets.
    pub task: TaskId,
    /// Solution snapshot being submitted.
    pub solution: SolutionId,
    /// Hash of the exact byte string sent (preview/test/copy/submit agree).
    pub source_sha256: String,
    /// Official `AtCoder` language ID selected for the submission.
    pub language_id: String,
    /// Current state-machine position.
    pub state: SubmissionState,
    /// Final judge verdict once [`SubmissionState::Completed`].
    pub verdict: Option<JudgeVerdict>,
    /// Official submission identifier once accepted.
    pub official_id: Option<String>,
    /// When the intent was recorded.
    pub created_at: SystemTime,
    /// When the record last changed state.
    pub updated_at: SystemTime,
}