/*
 * 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};

/// DtStatusResponse : Dependency-Track integration status surfaced to the frontend.  `healthy` is the boolean the existing UI already binds to. The new `error_status` and `error_message` fields let the UI distinguish a genuine \"DT replied OK with no findings\" state from \"DT is down or misconfigured\" (issue #963). When `healthy = true` both error fields are None; when `healthy = false`:   - `error_status = Some(401)`: auth failure (check API key)   - `error_status = Some(5xx)`: upstream is broken   - `error_status = None`:     transport failure (DT pod unreachable)   - `error_message`:           operator-facing failure description
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct DtStatusResponse {
    #[serde(rename = "enabled")]
    pub enabled: bool,
    /// Human-readable explanation when `healthy = false`. Safe to surface in the UI; does not leak credentials.
    #[serde(rename = "error_message", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub error_message: Option<Option<String>>,
    /// Upstream HTTP status if the health probe got a response, else None. Only populated when `healthy = false`.
    #[serde(rename = "error_status", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub error_status: Option<Option<i32>>,
    #[serde(rename = "healthy")]
    pub healthy: bool,
    #[serde(rename = "url", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub url: Option<Option<String>>,
}

impl DtStatusResponse {
    /// Dependency-Track integration status surfaced to the frontend.  `healthy` is the boolean the existing UI already binds to. The new `error_status` and `error_message` fields let the UI distinguish a genuine \"DT replied OK with no findings\" state from \"DT is down or misconfigured\" (issue #963). When `healthy = true` both error fields are None; when `healthy = false`:   - `error_status = Some(401)`: auth failure (check API key)   - `error_status = Some(5xx)`: upstream is broken   - `error_status = None`:     transport failure (DT pod unreachable)   - `error_message`:           operator-facing failure description
    pub fn new(enabled: bool, healthy: bool) -> DtStatusResponse {
        DtStatusResponse {
            enabled,
            error_message: None,
            error_status: None,
            healthy,
            url: None,
        }
    }
}

