/*
 * Artifact Keeper API
 *
 * Enterprise artifact registry supporting 45+ package formats.  ## Authentication  The JSON management API under `/api/v1/_*` accepts **API tokens only as `Authorization: Bearer <token>`**. This is the canonical scheme for programmatic access; JWTs issued by the login flow also use `Bearer`. HTTP Basic credentials on `/api/v1/_*` are validated *only* as a real `username:password` login — the password half is **not** retried as an API token. A request to `/api/v1/_*` that sends an API token in the password field of Basic auth therefore returns `401 AUTH_ERROR`; switch to `Authorization: Bearer <token>`.  Format (package-manager) endpoints such as `/v2/_*` (OCI), `/incus/_*`, `/debian/_*`, and the language registries are intentionally more permissive for client compatibility: in addition to Bearer, they accept HTTP **Basic** auth with the API token supplied in the *password* field (any username), matching the `pip` netrc / Artifactory-style `token:<api_token>` convention used by package managers that cannot send a Bearer header. This Basic-with-token fallback applies to format endpoints only, never to `/api/v1/_*`.
 *
 * The version of the OpenAPI document: 1.4.1
 * 
 * Generated by: https://openapi-generator.tech
 */

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

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct ArtifactResponse {
    /// Whether this artifact can have an SBOM generated or a security scan run against it. `false` for proxy-cached (Remote) objects: those are listed with a synthetic, SHA-256-derived id (see [`cached_artifact_id`]) and have no row in the `artifacts` table (#1280/#1278), so SBOM/scan lookups by `artifacts.id` cannot resolve them and `sbom_documents`/`scan_results` cannot reference them. `true` for hosted artifacts, which carry a real DB id. The web UI uses this to hide/disable the \"Generate SBOM\" / \"Scan\" actions where they cannot work; clients that predate the field should treat an absent value as `true` so hosted artifacts are never hidden. (#2227)
    #[serde(rename = "analyzable")]
    pub analyzable: bool,
    /// When the proxy cache entry for this artifact was last written. Only populated for Remote (proxy) repositories whose proxy service is configured AND that have a cache-metadata blob for this path. None for Local / Virtual / Staging repos and for Remote repos whose cache hasn't been populated yet (e.g. an artifact that exists as a DB row from a direct upload but has never been fetched through the proxy). (#1541)
    #[serde(rename = "cache_cached_at", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub cache_cached_at: Option<Option<String>>,
    /// When the proxy cache entry for this artifact will expire and be re-validated against upstream. Same gating as `cache_cached_at`. (#1541)
    #[serde(rename = "cache_expires_at", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub cache_expires_at: Option<Option<String>>,
    #[serde(rename = "checksum_sha256")]
    pub checksum_sha256: String,
    #[serde(rename = "content_type")]
    pub content_type: String,
    #[serde(rename = "created_at")]
    pub created_at: String,
    #[serde(rename = "download_count")]
    pub download_count: i64,
    #[serde(rename = "id")]
    pub id: uuid::Uuid,
    #[serde(rename = "metadata", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub metadata: Option<Option<serde_json::Value>>,
    #[serde(rename = "name")]
    pub name: String,
    #[serde(rename = "path")]
    pub path: String,
    #[serde(rename = "repository_key")]
    pub repository_key: String,
    #[serde(rename = "size_bytes")]
    pub size_bytes: i64,
    #[serde(rename = "version", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub version: Option<Option<String>>,
}

impl ArtifactResponse {
    pub fn new(analyzable: bool, checksum_sha256: String, content_type: String, created_at: String, download_count: i64, id: uuid::Uuid, name: String, path: String, repository_key: String, size_bytes: i64) -> ArtifactResponse {
        ArtifactResponse {
            analyzable,
            cache_cached_at: None,
            cache_expires_at: None,
            checksum_sha256,
            content_type,
            created_at,
            download_count,
            id,
            metadata: None,
            name,
            path,
            repository_key,
            size_bytes,
            version: None,
        }
    }
}

