variable "region" {
  default = "us-east-1"
}

variable "environment" {
  default = "prod"
}

variable "service_name" {
  default = "songwhip-presaves"
}

variable "team_name" {
  default = "songwhip"
}

variable "application_family" {
  default = "songwhip"
}

variable "auth0_m2m_audience" {
  default = "https://workstation.theorchard.com/api"
}

variable "auth0_m2m_client_id" {
  default = "6RacHdly4OlKQMhSTZVtAKDONtV6fard"
}

variable "auth0_m2m_base_url" {
  default = "https://workstation.auth0.com"
}

variable "secrets_manager_secret_names" {
  description = "List of secrets manager secrets to create"
  type        = list(string)
  default = [
    "PRESAVES_DB_USER",
    "PRESAVES_DB_PASSWORD",
    "AUTH0_M2M_CLIENT_SECRET",
    "WEBHOOK_TOKEN"
  ]
}

variable "sqs_max_message_size" {
  description = "The maximum sqs message size for presave tasks"
  default     = 1024 * 10 // 10KB
}

variable "presave_store_clients" {
  description = "DSP stores mapped to one or more client IDs (one SQS queue / client secret per client)."
  type        = map(list(string))
  default = {
    test         = ["test"]
    spotify      = ["5ba39d4de28f418ab77932d80aab3171"]
    apple-music  = ["U3KY7PPMM6"]
    deezer       = ["638401"]
    amazon-music = ["59f09b3a8f2748b9bec958f7b621603e"]
    email        = ["default"]
  }
}

variable "presave_service_defaults" {
  description = "Baseline Lambda config for all DSPs"
  type = object({
    timeout              = number      # Lambda timeout in seconds
    memory_size          = number      # Lambda memory in MB
    reserved_concurrency = number      # Reserved concurrent executions
    batch_size           = number      # SQS batch size per invoke
    batch_window         = number      # SQS batch window in seconds
    env_overrides        = map(string) # Extra env vars merged into the function
  })
  default = {
    timeout              = 300 # seconds before timing out
    memory_size          = 512 # MB
    reserved_concurrency = 2   # Max 2 concurrent lambdas
    batch_size           = 20  # Max 20 messages per batch
    batch_window         = 5   # Wait up to 5 seconds to collect batch
    env_overrides = {
      # Number of concurrent API requests each Lambda can make, 
      # used to control rate of requests to external APIs
      EXECUTION_CONCURRENCY = "1"
    }
  }
}

variable "presave_service_configs" {
  description = "Optional per-DSP Lambda config overrides"
  type = map(object({
    timeout              = optional(number)
    memory_size          = optional(number)
    reserved_concurrency = optional(number)
    batch_size           = optional(number)
    batch_window         = optional(number)
    env_overrides        = optional(map(string))
  }))
  default = {
    spotify = {
      // Target: 2 instances * 5 concurrent requests / (0.3s per op + 0.2s overhead) = ~20 RPS
      reserved_concurrency = 2,
      env_overrides = {
        EXECUTION_CONCURRENCY = "5"
      }
    }
    apple-music = {
      // Target: 3 instances * 5 concurrent requests / (0.3s per op + 0.2s overhead) = ~30 RPS
      reserved_concurrency = 3,
      env_overrides = {
        EXECUTION_CONCURRENCY = "5"
      }
    }
    amazon-music = {
      // Target: 4 instances * 5 concurrent requests / (1.0s per op + 0.2s overhead) = ~16 RPS
      reserved_concurrency = 4,
      env_overrides = {
        EXECUTION_CONCURRENCY = "5"
      }
    }
    deezer = {
      // Target: 4 instances * 5 concurrent requests / (0.2s per op + 0.2s overhead) = ~50 RPS
      reserved_concurrency = 4,
      env_overrides = {
        EXECUTION_CONCURRENCY = "5"
      }
    }
    test = {
      // Target: 4 instances * 5 concurrent requests / (0.3s per op + 0.2s overhead) = ~40 RPS
      reserved_concurrency = 4,
      env_overrides = {
        EXECUTION_CONCURRENCY = "5"
      }
    }
    email = {
      # Our PROD SES sending limit is 500 emails per second.
      # Keeping it a bit lower to not cause issues for other services using the same SES account.
      batch_size           = 50
      reserved_concurrency = 8,
      env_overrides = {
        SONGWHIP_WEB_URL = "https://songwhip.com"
      }
    }
  }
}

variable "rds_ingress_cidr_blocks" {
  description = "Allowed source IP addresses for the RDS DB (VPN)"
  default = [
    "192.168.32.0/24",
    "192.168.33.0/24",
    "192.168.40.0/22",
    "10.30.0.0/22",
    "10.40.0.0/22",
    "10.10.40.0/22",
    "10.141.0.0/29",
    "10.100.2.0/23",
    "10.100.12.0/23",
  ]
}
