use std::{
collections::BTreeMap,
path::{Path, PathBuf},
};
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct ResolvedIcydbConfig {
config_path: Option<PathBuf>,
config: GeneratedIcydbConfig,
}
impl ResolvedIcydbConfig {
#[must_use]
pub fn config_path(&self) -> Option<&Path> {
self.config_path.as_deref()
}
#[must_use]
pub const fn config(&self) -> &GeneratedIcydbConfig {
&self.config
}
pub(crate) const fn new(config_path: Option<PathBuf>, config: GeneratedIcydbConfig) -> Self {
Self {
config_path,
config,
}
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct GeneratedIcydbConfig {
canisters: BTreeMap<String, GeneratedCanisterConfig>,
}
impl GeneratedIcydbConfig {
#[must_use]
pub const fn canisters(&self) -> &BTreeMap<String, GeneratedCanisterConfig> {
&self.canisters
}
#[must_use]
pub fn canister_sql_readonly_enabled(&self, canister_name: &str) -> bool {
self.canisters
.get(canister_name)
.is_some_and(GeneratedCanisterConfig::sql_readonly)
}
#[must_use]
pub fn canister_sql_ddl_enabled(&self, canister_name: &str) -> bool {
self.canisters
.get(canister_name)
.is_some_and(GeneratedCanisterConfig::sql_ddl)
}
#[must_use]
pub fn canister_sql_fixtures_enabled(&self, canister_name: &str) -> bool {
self.canisters
.get(canister_name)
.is_some_and(GeneratedCanisterConfig::sql_fixtures)
}
#[must_use]
pub fn canister_metrics_enabled(&self, canister_name: &str) -> bool {
self.canisters
.get(canister_name)
.is_some_and(GeneratedCanisterConfig::metrics)
}
#[must_use]
pub fn canister_metrics_reset_enabled(&self, canister_name: &str) -> bool {
self.canisters
.get(canister_name)
.is_some_and(GeneratedCanisterConfig::metrics_reset)
}
#[must_use]
pub fn canister_snapshot_enabled(&self, canister_name: &str) -> bool {
self.canisters
.get(canister_name)
.is_some_and(GeneratedCanisterConfig::snapshot)
}
#[must_use]
pub fn canister_schema_enabled(&self, canister_name: &str) -> bool {
self.canisters
.get(canister_name)
.is_some_and(GeneratedCanisterConfig::schema)
}
pub(crate) const fn new(canisters: BTreeMap<String, GeneratedCanisterConfig>) -> Self {
Self { canisters }
}
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct GeneratedCanisterConfig {
sql: GeneratedCanisterSqlConfig,
metrics: GeneratedCanisterMetricsConfig,
snapshot: bool,
schema: bool,
}
impl GeneratedCanisterConfig {
pub(crate) const fn new(
sql: GeneratedCanisterSqlConfig,
metrics: GeneratedCanisterMetricsConfig,
snapshot: bool,
schema: bool,
) -> Self {
Self {
sql,
metrics,
snapshot,
schema,
}
}
#[must_use]
pub const fn sql_readonly(&self) -> bool {
self.sql.readonly
}
#[must_use]
pub const fn sql_ddl(&self) -> bool {
self.sql.ddl
}
#[must_use]
pub const fn sql_fixtures(&self) -> bool {
self.sql.fixtures
}
#[must_use]
pub const fn metrics(&self) -> bool {
self.metrics.enabled
}
#[must_use]
pub const fn metrics_reset(&self) -> bool {
self.metrics.reset
}
#[must_use]
pub const fn snapshot(&self) -> bool {
self.snapshot
}
#[must_use]
pub const fn schema(&self) -> bool {
self.schema
}
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub(crate) struct GeneratedCanisterSqlConfig {
readonly: bool,
ddl: bool,
fixtures: bool,
}
impl GeneratedCanisterSqlConfig {
pub(crate) const fn new(readonly: bool, ddl: bool, fixtures: bool) -> Self {
Self {
readonly,
ddl,
fixtures,
}
}
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub(crate) struct GeneratedCanisterMetricsConfig {
enabled: bool,
reset: bool,
}
impl GeneratedCanisterMetricsConfig {
pub(crate) const fn new(enabled: bool, reset: bool) -> Self {
Self { enabled, reset }
}
}