/*
 * Cube.js
 *
 * Cube.js Swagger Schema
 *
 * The version of the OpenAPI document: 1.0.0
 *
 * Generated by: https://openapi-generator.tech
 *
 * Hand-maintained: this file is generic over the `data` payload type so that
 * callers who know the wire format (e.g. row vs compact vs columnar) can
 * deserialize directly into the concrete type and skip the buffered re-parse
 * that `#[serde(untagged)]` on `V1LoadResultData` would otherwise impose.
 * Default `D` is `V1LoadResultDataRow` — the format that `load_v1` requests
 * by default.
 */

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

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct V1LoadResult<D = models::V1LoadResultDataRow> {
    #[serde(rename = "dataSource", skip_serializing_if = "Option::is_none")]
    pub data_source: Option<String>,
    #[serde(rename = "annotation")]
    pub annotation: Box<models::V1LoadResultAnnotation>,
    #[serde(rename = "data")]
    pub data: D,
    #[serde(rename = "refreshKeyValues", skip_serializing_if = "Option::is_none")]
    pub refresh_key_values: Option<Vec<serde_json::Value>>,
    #[serde(rename = "lastRefreshTime", skip_serializing_if = "Option::is_none")]
    pub last_refresh_time: Option<String>,
    /// `true` when the result was served from an external (CubeStore)
    /// pre-aggregation — the case where cache freshness on the cubesql
    /// side actually depends on the pre-agg refresh, as internal
    /// pre-aggregations hit the source DB and rely on its own caching.
    #[serde(rename = "external", skip_serializing_if = "Option::is_none")]
    pub external: Option<bool>,
}

impl<D: Default> Default for V1LoadResult<D> {
    fn default() -> Self {
        Self {
            data_source: None,
            annotation: Box::new(models::V1LoadResultAnnotation::default()),
            data: D::default(),
            refresh_key_values: None,
            last_refresh_time: None,
            external: None,
        }
    }
}

impl<D> V1LoadResult<D> {
    pub fn new(annotation: models::V1LoadResultAnnotation, data: D) -> V1LoadResult<D> {
        V1LoadResult {
            data_source: None,
            annotation: Box::new(annotation),
            data,
            refresh_key_values: None,
            last_refresh_time: None,
            external: None,
        }
    }
}
