use dprint_core::configuration::ConfigKeyMap;
use dprint_core::configuration::ConfigKeyValue;
use indexmap::IndexMap;

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct RawPluginConfigOverride {
  pub files: Vec<String>,
  pub properties: ConfigKeyMap,
}

/// Unresolved plugin configuration.
#[derive(Clone, PartialEq, Eq, Debug, Default)]
pub struct RawPluginConfig {
  pub associations: Option<Vec<String>>,
  pub locked: bool,
  pub overrides: Vec<RawPluginConfigOverride>,
  pub properties: ConfigKeyMap,
}

#[derive(Clone, PartialEq, Eq, Debug)]
pub enum ConfigMapValue {
  KeyValue(ConfigKeyValue),
  PluginConfig(RawPluginConfig),
  Vec(Vec<String>),
}

impl ConfigMapValue {
  pub fn from_i32(value: i32) -> ConfigMapValue {
    ConfigMapValue::KeyValue(ConfigKeyValue::from_i32(value))
  }

  #[cfg(test)]
  pub fn from_str(value: &str) -> ConfigMapValue {
    ConfigMapValue::KeyValue(ConfigKeyValue::from_str(value))
  }

  pub fn from_bool(value: bool) -> ConfigMapValue {
    ConfigMapValue::KeyValue(ConfigKeyValue::from_bool(value))
  }
}

pub type ConfigMap = IndexMap<String, ConfigMapValue>;
