package gs.config.v0.audit

import gs.config.v0.ConfigError

/** Describes queries used to find configuration. Used for auditing purposes and
  * is captured by [[ConfigManifest]].
  */
sealed trait ConfigQueryResult

object ConfigQueryResult:

  given CanEqual[ConfigQueryResult, ConfigQueryResult] = CanEqual.derived

  /** Represents a query for some configuration that completed successfully.
    *
    * @param source
    *   The name of the source which provided the value.
    * @param rawValue
    *   The raw value that the source returned.
    */
  case class Success(
    source: Option[String],
    rawValue: String
  ) extends ConfigQueryResult

  /** Represents a query for some configuration that did not find the value in
    * any source, but was able to use a default value.
    *
    * @param checkedSources
    *   The list of sources that were checked before selecting the default
    *   value.
    */
  case class UsedDefault(
    checkedSources: List[String]
  ) extends ConfigQueryResult

  /** Represents a query for some configuration that failed.
    *
    * @param sources
    *   List of all sources, in order, that were consulted to attempt to get
    *   this value. Note that a failure short-circuits lookup, so this list will
    *   not include any subsequent candidate sources.
    * @param error
    *   The reason why this query failed.
    */
  case class Failure(
    sources: List[String],
    error: ConfigError
  ) extends ConfigQueryResult

end ConfigQueryResult