locals {
  complete_escal_notify_lambda_name = "${var.service_name}-complete-escalation-notify"
}

module "lambda_content_complete_escalation_notify_owsrequest" {
  source = "git@github.com:theorchard/terraform-owsrequest.git//?ref=1.0.1"

  environment_name = var.environment
  service_name     = local.complete_escal_notify_lambda_name
}

module "lambda_content_complete_escalation_notify" {
  source = "git@github.com:theorchard/terraform-lambda.git//?ref=4.3.0"

  environment        = var.environment
  application_family = var.application_family
  lambda_name        = local.complete_escal_notify_lambda_name

  use_container_image      = true
  lambda_description       = "Notify user of the approval/ rejection of an escalated product."
  lambda_function_timeout  = "600"
  vpc_enabled              = true
  vpc_id                   = module.vpc_info.vpc_id
  vpc_subnet_ids           = module.vpc_info.default_private_subnet_ids
  datadog_enabled          = true
  datadog_advanced_enabled = true
  additional_tags          = var.additional_tags

  lambda_function_environment_variables = {
    ENVIRONMENT              = var.environment
    SENTRY_DSN               = module.sentry_lambda_content_complete_escalation_notify.sentry_key_dsn_public_output
    GRAPHQL_GATEWAY_URL      = var.graphql_gateway_url
    SYSTEM_USER_IDENTITY_ID  = "133b3139-6975-4c01-a9d8-e490668f0143"
    SYSTEM_USER_PROFILE_ID   = "666388"
    SYSTEM_USER_PROFILE_TYPE = "ContentProfile"
  }

  msk_event_enabled                      = true
  event_source_mapping_msk_cluster_name  = var.trigger_msk_cluster_name
  event_source_mapping_msk_cluster_uuid  = var.trigger_msk_cluster_uuid
  event_source_mapping_batch_size        = 1
  kafka_topics                           = [var.product_review_msk_topic]
  event_source_mapping_starting_position = "LATEST"

  iam_managed_policy_attachments = [
    module.lambda_content_complete_escalation_notify_owsrequest.policy_arn_output
  ]
}

# stage datadog creds and create dashboards.
module "datadog_lambda_content_complete_escalation_notify" {
  source = "git@github.com:theorchard/terraform-datadog.git//modules/lambda?ref=6.13.9"

  environment                       = var.environment
  service_name                      = local.complete_escal_notify_lambda_name
  notification_endpoints            = var.notification_endpoints
  escalation_notification_endpoints = var.escalation_notification_endpoints
}

module "sentry_lambda_content_complete_escalation_notify" {
  source = "git@github.com:theorchard/terraform-sentry.git//?ref=4.1.2"

  environment        = var.environment
  service_name       = local.complete_escal_notify_lambda_name
  application_family = var.application_family
}
