openai-client-base 0.16.0

Auto-generated Rust client for the OpenAI API
/*
 * OpenAI API
 *
 * The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
 *
 * The version of the OpenAPI document: 2.3.0
 *
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

/// ProjectApiKey : Represents an individual API key in a project.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct ProjectApiKey {
    /// The object type, which is always `organization.project.api_key`
    #[serde(rename = "object")]
    pub object: Object,
    /// The redacted value of the API key
    #[serde(rename = "redacted_value")]
    pub redacted_value: String,
    /// The name of the API key
    #[serde(rename = "name")]
    pub name: String,
    /// The Unix timestamp (in seconds) of when the API key was created
    #[serde(rename = "created_at")]
    pub created_at: i32,
    #[serde(
        rename = "expires_at",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub expires_at: Option<Option<i32>>,
    #[serde(rename = "last_used_at", deserialize_with = "Option::deserialize")]
    pub last_used_at: Option<i32>,
    /// The identifier, which can be referenced in API endpoints
    #[serde(rename = "id")]
    pub id: String,
    /// Whether the API key's owner currently has effective access to the project.
    #[serde(rename = "owner_project_access")]
    pub owner_project_access: OwnerProjectAccess,
    #[serde(rename = "owner")]
    pub owner: Box<models::ProjectApiKeyOwner>,
}

impl ProjectApiKey {
    /// Represents an individual API key in a project.
    pub fn new(
        object: Object,
        redacted_value: String,
        name: String,
        created_at: i32,
        last_used_at: Option<i32>,
        id: String,
        owner_project_access: OwnerProjectAccess,
        owner: models::ProjectApiKeyOwner,
    ) -> ProjectApiKey {
        ProjectApiKey {
            object,
            redacted_value,
            name,
            created_at,
            expires_at: None,
            last_used_at,
            id,
            owner_project_access,
            owner: Box::new(owner),
        }
    }
}
/// The object type, which is always `organization.project.api_key`
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Object {
    #[serde(rename = "organization.project.api_key")]
    OrganizationProjectApiKey,
}

impl Default for Object {
    fn default() -> Object {
        Self::OrganizationProjectApiKey
    }
}
/// Whether the API key's owner currently has effective access to the project.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum OwnerProjectAccess {
    #[serde(rename = "active")]
    Active,
    #[serde(rename = "inactive")]
    Inactive,
}

impl Default for OwnerProjectAccess {
    fn default() -> OwnerProjectAccess {
        Self::Active
    }
}

impl std::fmt::Display for ProjectApiKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match serde_json::to_string(self) {
            Ok(s) => write!(f, "{}", s),
            Err(_) => Err(std::fmt::Error),
        }
    }
}