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

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

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

variable "application_family" {
  default = "vector"
}

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

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

variable "s3_bucket_direct_delivery" {
  type        = string
  description = "Types of assets to use for S3 bucket lookup"
  default     = "direct-delivery"
}

variable "config_s3_bucket_suffix" {
  description = "S3 bucket where encrypted content is stored"
  default     = "supply-chain-staged-configs"
}

variable "audio_encoder_id" {
  default = "18"
}

variable "video_encoder_id" {
  default = "17"
}

variable "physical_location_dms_include" {
  type        = map(string)
  description = "Comma separated list of DMS IDs to include"
  default = {
    "9" : "1,1223,500,1810",
    "10" : "465,252"
  }
}

# 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
}

variable "extended_ddex_api_gateway_url" {
  default = "ul7vwqbzwa-vpce-04f8c4be29fb2bd59.execute-api.us-east-1.amazonaws.com"
}

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    = "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 "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"
    }
  ]
}

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 = concat(
    [
      for policy in var.physical_location_ids : {
        policy_name = "S3-${var.environment}-supply-chain-encoding-${var.s3_bucket_direct_delivery}-physical-location-${policy}-RO-policy"
      }
    ],
    [
      for policy in var.physical_location_ids : {
        policy_name = "S3-${var.environment}-supply-chain-encoding-${var.s3_bucket_direct_delivery}-physical-location-${policy}-RW-policy"
      }
    ]
  )
}

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