variable "aws_region" {
  default     = "us-east-1"
  description = "AWS region"
}

variable "environment" {
  description = "Available values:  dev, qa, prod."
  default     = "qa"
}

variable "s3_video_bucket" {
  default = "qa-orcd-video-assets"
}

variable "s3_mezz_bucket" {
  default = "qa-orcd-mezzanine-assets"
}

variable "service_name" {
  default = "vector-encoder"
}

variable "application_family" {
  default = "vector"
}

variable "team_name" {
  type        = string
  description = "Name of team that owns the service"
  default     = "content-delivery-asset-management"
}

variable "app_log_level" {
  type        = string
  description = "Application log level"
  default     = "Debug"
}

variable "audio_encoder_id" {
  default = "18"
}

variable "video_encoder_id" {
  default = "17"
}

variable "physical_location_ids" {
  type        = set(string)
  description = "List of physical location IDs to use when creating resources"
  default = [
    "9",
  ]
}

variable "s3_bucket_asset_types" {
  type        = set(string)
  description = "Types of assets to use for S3 bucket lookup"
  default = [
    "direct-delivery",
  ]
}

variable "audio_service_name_to_encoding_priority" {
  type = set(object({
    encoding_priority = string,
    min_task_count    = string,
    max_task_count    = string,
  }))
  default = [
    {
      encoding_priority = "1"
      min_task_count    = "1"
      max_task_count    = "8"
    },
    {
      encoding_priority = "2"
      min_task_count    = "1"
      max_task_count    = "8"
    },
    {
      encoding_priority = "3"
      min_task_count    = "1"
      max_task_count    = "8"
    },
    {
      encoding_priority = "4"
      min_task_count    = "1"
      max_task_count    = "8"
    },
    {
      encoding_priority = "5"
      min_task_count    = "1"
      max_task_count    = "8"
    },
    {
      encoding_priority = "6"
      min_task_count    = "1"
      max_task_count    = "8"
    }
  ]
}

variable "video_service_name_to_encoding_priority" {
  type = set(object({
    encoding_priority = string,
    min_task_count    = string,
    max_task_count    = string,
  }))
  default = [
    {
      encoding_priority = "1"
      min_task_count    = "0"
      max_task_count    = "8"
    },
    {
      encoding_priority = "2"
      min_task_count    = "0"
      max_task_count    = "8"
    },
    {
      encoding_priority = "3"
      min_task_count    = "0"
      max_task_count    = "8"
    },
    {
      encoding_priority = "4"
      min_task_count    = "0"
      max_task_count    = "8"
    },
    {
      encoding_priority = "5"
      min_task_count    = "0"
      max_task_count    = "8"
    },
    {
      encoding_priority = "6"
      min_task_count    = "0"
      max_task_count    = "8"
    }
  ]
}

variable "secrets_manager_secret_names" {
  type        = set(string)
  description = "List of secret names to create in secrets manager with the same settings"
  default = [
    "AR_DB_PASSWORD",
    "DD_DB_RO_PASSWORD",
    "DD_DB_RW_PASSWORD",
    "DD_DB_EO_PASSWORD",
    "AWS_KEY_ID",
    "AWS_SECRET_KEY",
  ]
}

# Scaling variables
variable "scaling_cooldown_period_seconds" {
  description = "Scaling cooldown period in seconds."
  default     = 30
}

variable "scale_up_adjustment" {
  description = "Number of tasks to add in response to cloudwatch alarm."
  default     = 4
}

variable "scale_down_adjustment" {
  description = "Number of tasks to remove when alarm is in OK status."
  default     = -4
}

locals {
  tags = {
    environment        = var.environment
    service_name       = var.service_name
    application_family = var.application_family
    terraformed        = true
  }

  flattened_audio_service_list = [
    for obj in setproduct(var.physical_location_ids, var.audio_service_name_to_encoding_priority) : {
      physical_location = obj[0]
      encoding_priority = obj[1]["encoding_priority"]
      min_task_count    = obj[1]["min_task_count"]
      max_task_count    = obj[1]["max_task_count"]
    }
  ]

  flattened_video_service_list = [
    for obj in setproduct(var.physical_location_ids, var.video_service_name_to_encoding_priority) : {
      physical_location = obj[0]
      encoding_priority = obj[1]["encoding_priority"]
      min_task_count    = obj[1]["min_task_count"]
      max_task_count    = obj[1]["max_task_count"]
    }
  ]


  s3_policies_to_attach = [
    for policy_combination in setproduct(var.s3_bucket_asset_types, var.physical_location_ids) : {
      policy_name = "S3-${var.environment}-encoding-${policy_combination[0]}-physical-location-${policy_combination[1]}-RW-policy"
    }
  ]
}
