//! Credential request response types.

use std::fmt;

use serde::{Deserialize, Serialize};

use crate::types::RequestId;

/// Response from creating a credential presentation request.
///
/// Contains all information needed to present a QR code to the user
/// and poll for completion.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CredentialRequestResponse {
    /// Unique identifier for this request (for polling)
    pub request_id: RequestId,

    /// `OpenID4VP` request URI for QR code display.
    ///
    /// This is the `openid4vp://` URL that the mobile app scans
    /// to retrieve the presentation request details.
    pub request_uri: String,

    /// Request expiration time in seconds from creation.
    pub expires_in: u64,

    /// Cryptographic nonce for replay protection.
    pub nonce: String,
}

impl CredentialRequestResponse {
    /// Create a new credential request response.
    #[must_use]
    pub const fn new(
        request_id: RequestId,
        request_uri: String,
        expires_in: u64,
        nonce: String,
    ) -> Self {
        Self {
            request_id,
            request_uri,
            expires_in,
            nonce,
        }
    }

    /// Get the request ID for polling.
    #[must_use]
    pub const fn request_id(&self) -> &RequestId {
        &self.request_id
    }

    /// Get the `OpenID4VP` request URI for QR code display.
    #[must_use]
    pub fn request_uri(&self) -> &str {
        &self.request_uri
    }

    /// Get the expiration time in seconds.
    #[must_use]
    pub const fn expires_in(&self) -> u64 {
        self.expires_in
    }

    /// Get the nonce for verification.
    #[must_use]
    pub fn nonce(&self) -> &str {
        &self.nonce
    }
}

impl fmt::Display for CredentialRequestResponse {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "CredentialRequestResponse {{ request_id: {}, expires_in: {}s }}",
            self.request_id, self.expires_in
        )
    }
}
