/*******************************************************************************
 *
 *    Copyright (c) 2025 - 2026.
 *    Haixing Hu, Qubit Co. Ltd.
 *
 *    All rights reserved.
 *
 ******************************************************************************/
//! Attempt failure decisions.

use std::time::Duration;

use serde::{Deserialize, Serialize};

/// Decision returned by a retry failure listener after inspecting a failure.
///
/// Explicit retry decisions still obey attempt and elapsed-time limits.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum AttemptFailureDecision {
    /// Use the retry policy's default decision for this failure.
    UseDefault,
    /// Retry the operation if limits still allow it.
    Retry,
    /// Retry after the specified delay if limits still allow it.
    RetryAfter(
        /// Delay selected by the listener.
        #[serde(with = "qubit_common::serde::duration_millis")]
        Duration,
    ),
    /// Abort immediately and return the current failure.
    Abort,
}

impl Default for AttemptFailureDecision {
    /// Returns the default decision.
    ///
    /// # Returns
    /// [`AttemptFailureDecision::UseDefault`].
    #[inline]
    fn default() -> Self {
        Self::UseDefault
    }
}
