locals {
  hive_ai_image_detection_lambda_name = "${var.lambda_service_name}-hive-ai-image-detection"
}

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

  environment         = var.environment
  application_family  = var.application_family
  use_container_image = true
  lambda_name         = local.hive_ai_image_detection_lambda_name
  lambda_description  = "Calls Hive to perform AI detection on images/ visual content."

  lambda_function_environment_variables = {
    Environment = var.environment
    SENTRY_DSN  = module.sentry_lambda_hive_ai_image_detection.sentry_key_dsn_public_output
  }

  msk_event_enabled                      = false
  event_source_mapping_msk_cluster_name  = var.cdc_msk_cluster_name
  event_source_mapping_msk_cluster_uuid  = var.cdc_msk_cluster_uuid
  event_source_mapping_batch_size        = 1
  kafka_topics                           = [var.msk_asset_mezzanine_coverart_topic_name]
  event_source_mapping_starting_position = "LATEST"

  lambda_function_timeout                        = "300"
  vpc_enabled                                    = true
  vpc_id                                         = module.vpc_info.vpc_id
  vpc_subnet_ids                                 = module.vpc_info.default_private_subnet_ids
  lambda_function_reserved_concurrent_executions = 2
  datadog_advanced_enabled                       = true
  datadog_enabled                                = true
}

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

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

module "datadog_lambda_hive_ai_image_detection" {
  source = "git@github.com:theorchard/terraform-datadog.git//modules/lambda?ref=6.18.1"

  environment                       = var.environment
  service_name                      = local.hive_ai_image_detection_lambda_name
  lambda_invocation_monitor_enabled = false
  lambda_error_monitor_enabled      = false
  notification_endpoints            = var.notification_endpoints
}

module "hive_ai_image_detection_credentials" {
  source = "git@github.com:theorchard/terraform-secrets-manager.git//?ref=1.5.1"

  secret_name        = "HIVE_API_KEY"
  environment        = var.environment
  service_name       = local.hive_ai_image_detection_lambda_name
  application_family = var.application_family
}

module "hive_ai_image_detection_m2m_secret" {
  source = "git@github.com:theorchard/terraform-secrets-manager.git//modules/auth0m2m?ref=1.6.1"

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