package config

import zio.Config
import zio.config.magnolia.deriveConfig

/** Server configuration
  *
  * @param host
  *   Server bind host
  * @param port
  *   Server bind port
  */
final case class ServerConfig(
    host: String,
    port: Int
)

object ServerConfig {
  given config: Config[ServerConfig] = deriveConfig[ServerConfig]
}

/** Database configuration
  *
  * @param host
  *   Database host
  * @param port
  *   Database port
  * @param database
  *   Database name
  * @param user
  *   Database user
  * @param password
  *   Database password
  */
final case class DatabaseConfig(
    host: String,
    port: Int,
    database: String,
    user: String,
    password: String
)

object DatabaseConfig {
  given config: Config[DatabaseConfig] = deriveConfig[DatabaseConfig]
}

/** Application configuration
  *
  * Composed from server and database configurations. Uses zio-config-magnolia for automatic
  * derivation.
  *
  * @param server
  *   Server configuration
  * @param database
  *   Database configuration
  */
final case class AppConfig(
    server: ServerConfig,
    database: DatabaseConfig
)

object AppConfig {
  given config: Config[AppConfig] = deriveConfig[AppConfig]
}
