use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub(crate) enum ParametersType {
Enabled(bool),
Named(String),
}
impl ParametersType {
pub fn is_enabled(&self) -> bool {
match self {
ParametersType::Enabled(b) => *b,
ParametersType::Named(_) => true,
}
}
pub fn get_struct_name(&self) -> Option<&str> {
match self {
ParametersType::Enabled(_) => None,
ParametersType::Named(name) => Some(name.as_str()),
}
}
}
impl Default for ParametersType {
fn default() -> Self {
ParametersType::Enabled(false)
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub(crate) enum ConditionsType {
Enabled(bool),
Named(String),
}
impl ConditionsType {
pub fn is_enabled(&self) -> bool {
match self {
ConditionsType::Enabled(b) => *b,
ConditionsType::Named(_) => true,
}
}
pub fn get_struct_name(&self) -> Option<&str> {
match self {
ConditionsType::Enabled(_) => None,
ConditionsType::Named(name) => Some(name.as_str()),
}
}
}
impl Default for ConditionsType {
fn default() -> Self {
ConditionsType::Enabled(false)
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub(crate) enum ExpectedResult {
ExactlyOne,
PossibleOne,
AtLeastOne,
Multiple,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum TelemetryLevel {
None,
Info,
Debug,
Trace,
}
impl Default for TelemetryLevel {
fn default() -> Self {
TelemetryLevel::None
}
}
impl Default for ExpectedResult {
fn default() -> Self {
ExpectedResult::ExactlyOne
}
}
#[derive(Debug, Clone)]
pub(crate) struct QueryDefinition {
pub name: String,
pub sql: String,
pub description: Option<String>,
pub module: String,
pub expect: ExpectedResult,
pub types: Option<HashMap<String, String>>,
pub telemetry: QueryTelemetryConfig,
pub ensure_indexes: bool,
pub multiunzip: bool,
pub conditions_type: ConditionsType,
pub parameters_type: ParametersType,
pub return_type: Option<String>,
pub error_type: Option<String>,
}
#[derive(Debug, Default, Clone)]
pub(crate) struct QueryTelemetryConfig {
pub level: TelemetryLevel,
pub include_params: Option<Vec<String>>,
pub include_sql: bool,
}