variable "wait_on" {
  type        = any
  description = "Resources to wait on"
  default     = true
}

variable "server_ip" {
  type = string
}

variable "ssh_private_key_path" {
  type = string
}

variable "server_domain" {
  type = string
}

module "mopidy" {
  source = "../quadlet-app"
  wait_on = var.wait_on

  server_ip            = var.server_ip
  ssh_private_key_path = var.ssh_private_key_path

  app_name = "mopidy"
  image    = "docker.io/ivdata/mopidy"
  ports    = ["6600:6600", "6680:6680"]
  volumes = [
    "/opt/storage/data/mopidy:/var/lib/mopidy:Z",
    "/opt/storage/data/mopidy/mopidy.conf:/home/mopidy/.config/mopidy/mopidy.conf:Z",
    "/opt/storage/media/music:/media/music:ro,Z",
  ]

  # environment = {
  #   SPOTIFY_CLIENT_ID="ff4a141c-cb52-4569-9848-c0468da66bd1"
  #   SPOTIFY_CLIENT_SECRET="VVXVtoiY8DanFLl9BnpHvLygXCchboHoEewoALTHIaA="
  # }

  haproxy_services = [
    {
      name   = "mopidy"
      domain = "mopidy.${var.server_domain}"
      port   = "6680"
      host   = "127.0.0.1"
      tls    = false
    },
  ]

}

output "app_urls" {
  value = module.mopidy.app_urls
}

output "installed" {
  value = true
  depends_on = [module.mopidy.installed]
}
