/*
 * Artifact Keeper API
 *
 * Enterprise artifact registry supporting 45+ package formats.
 *
 * The version of the OpenAPI document: 1.2.1
 * 
 * Generated by: https://openapi-generator.tech
 */

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

/// DockerTagResponse : A Docker/OCI tag grouped by (image, tag).  `total_size_bytes` is the server-side aggregation of the manifest body plus every referenced layer blob.  This is what the UI should display as the on-disk image size; the previous client-side aggregation that only summed the manifest body itself reported a few kilobytes for images that are hundreds of megabytes on disk (artifact-keeper#1193).  For multi-arch image indexes the size is the sum across all per-arch child manifests recorded in `oci_manifest_refs`, so an `amd64+arm64` index reports the combined storage cost.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct DockerTagResponse {
    /// Representative manifest artifact ID.
    #[serde(rename = "id")]
    pub id: uuid::Uuid,
    /// Image name (no registry host, no tag).  Maps to the OCI v2 `<name>` path segment, which may include slashes (e.g. `library/postgres`).
    #[serde(rename = "image")]
    pub image: String,
    /// Whether this manifest is a multi-arch image index.
    #[serde(rename = "is_index")]
    pub is_index: bool,
    /// Last push (or update) timestamp from the underlying `oci_tags` row.
    #[serde(rename = "last_pushed_at")]
    pub last_pushed_at: String,
    /// Number of layer blobs referenced by the manifest.  For image indexes this is the sum of layer counts across child manifests.  `0` when the manifest could not be parsed.
    #[serde(rename = "layer_count")]
    pub layer_count: i32,
    /// Manifest content digest (e.g. `sha256:abcdef...`).
    #[serde(rename = "manifest_digest")]
    pub manifest_digest: String,
    /// Repository key this tag belongs to.
    #[serde(rename = "repository_key")]
    pub repository_key: String,
    /// Rolled-up scan status across all scanners configured for this artifact. `None` when the artifact has never been scanned.  Values surface the aggregate state, not a single scanner's row (see #1497). One of:  * `pending` / `running` -- at least one scanner is still in flight * `completed` -- every per-scan-type latest row is `completed` * `failed` -- every per-scan-type latest row is `failed` * `partial` -- mixed: at least one `completed` AND at least one   `failed`. A green generic scanner (e.g. grype) no longer hides   a failed format-native scanner (e.g. incus) behind a   `completed` label.
    #[serde(rename = "scan_status", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub scan_status: Option<Option<String>>,
    /// Tag string (e.g. `16-alpine`).  Never a `sha256:...` digest; digest-only references are filtered out of the grouping.
    #[serde(rename = "tag")]
    pub tag: String,
    /// Total size in bytes of the manifest plus all referenced layer blobs. For image indexes, this sums across child manifests.
    #[serde(rename = "total_size_bytes")]
    pub total_size_bytes: i64,
}

impl DockerTagResponse {
    /// A Docker/OCI tag grouped by (image, tag).  `total_size_bytes` is the server-side aggregation of the manifest body plus every referenced layer blob.  This is what the UI should display as the on-disk image size; the previous client-side aggregation that only summed the manifest body itself reported a few kilobytes for images that are hundreds of megabytes on disk (artifact-keeper#1193).  For multi-arch image indexes the size is the sum across all per-arch child manifests recorded in `oci_manifest_refs`, so an `amd64+arm64` index reports the combined storage cost.
    pub fn new(id: uuid::Uuid, image: String, is_index: bool, last_pushed_at: String, layer_count: i32, manifest_digest: String, repository_key: String, tag: String, total_size_bytes: i64) -> DockerTagResponse {
        DockerTagResponse {
            id,
            image,
            is_index,
            last_pushed_at,
            layer_count,
            manifest_digest,
            repository_key,
            scan_status: None,
            tag,
            total_size_bytes,
        }
    }
}

