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

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

variable "application_family" {
  description = "Application family for default tags"
  type        = string
  default     = "resonance-engine"
}

variable "service_name" {
  description = "Service name for resource naming"
  type        = string
  default     = "resonance-engine"
}

variable "ddb_export_bucket_name" {
  description = "S3 bucket containing DynamoDB export files"
  type        = string
  default     = "dev-mymac80"
}

variable "ddb_export_prefix" {
  description = "S3 prefix for DynamoDB export data"
  type        = string
  default     = "resonance-engine/ddb-export/"
}

variable "sqs_message_retention_seconds" {
  description = "How long SQS retains messages (seconds)"
  type        = number
  default     = 86400 # 1 day
}

variable "sqs_visibility_timeout_seconds" {
  description = "SQS visibility timeout — should exceed expected batch processing time"
  type        = number
  default     = 420 # 7 minutes (fan-batch processing averages ~5.5 min)
}

variable "dlq_max_receive_count" {
  description = "Number of receives before moving message to DLQ"
  type        = number
  default     = 3
}

# -----------------------------------------------------------------------------
# Manifest Parser Lambda
# -----------------------------------------------------------------------------

variable "manifest_parser_timeout" {
  description = "Manifest Parser Lambda timeout (seconds). Increased for dispatcher mode: streams .json.gz files and sends fan batches."
  type        = number
  default     = 300
}

variable "manifest_parser_memory_size" {
  description = "Manifest Parser Lambda memory (MB)"
  type        = number
  default     = 512
}

variable "manifest_parser_concurrency" {
  description = "Manifest Parser Lambda reserved concurrency"
  type        = number
  default     = 1
}

variable "fan_batch_size" {
  description = "Number of fans per SQS message batch dispatched by the Manifest Parser"
  type        = number
  default     = 100

  validation {
    condition     = var.fan_batch_size > 0 && var.fan_batch_size <= 1000
    error_message = "fan_batch_size must be between 1 and 1000. At 500 fans the SQS message body is ~133KB; values above 1000 risk exceeding the 256KB SQS message size limit."
  }
}

# -----------------------------------------------------------------------------
# Collector Worker Lambda
# -----------------------------------------------------------------------------

variable "collector_worker_timeout" {
  description = "Collector Worker Lambda timeout (seconds) — must be <= sqs_visibility_timeout_seconds"
  type        = number
  default     = 420 # matches visibility timeout; batches complete in ~5.5 min
}

variable "collector_worker_memory_size" {
  description = "Collector Worker Lambda memory (MB)"
  type        = number
  default     = 512
}

variable "collector_worker_concurrency" {
  description = "Collector Worker Lambda reserved concurrency"
  type        = number
  default     = 15
}

variable "collector_worker_batch_size" {
  description = "SQS event source mapping batch size for Collector Worker"
  type        = number
  default     = 1
}

variable "collector_worker_esm_enabled" {
  description = "Enable SQS event source mapping — set to true after first ECR image push"
  type        = bool
  default     = false
}

variable "spotify_client_id" {
  description = "Spotify OAuth client ID — empty in dev disables collection. Required for prod (migrate to Secrets Manager)."
  type        = string
  sensitive   = true
  default     = ""
}

variable "spotify_client_secret" {
  description = "Spotify OAuth client secret — empty in dev disables collection. Required for prod (migrate to Secrets Manager)."
  type        = string
  sensitive   = true
  default     = ""
}

variable "kafka_bootstrap_servers" {
  description = "MSK bootstrap servers (comma-separated) — empty disables Kafka producing"
  type        = string
  default     = ""
}

variable "kafka_security_protocol" {
  description = "Kafka security protocol. SSL for TLS-only clusters, SASL_SSL for IAM auth."
  type        = string
  default     = "SSL"
}

variable "kafka_sasl_mechanism" {
  description = "Kafka SASL mechanism. Empty for TLS-only clusters, AWS_MSK_IAM for IAM auth."
  type        = string
  default     = ""
}

variable "kafka_topic" {
  description = "Kafka topic for Spotify data"
  type        = string
  default     = "resonance-engine.spotify-data"
}

variable "msk_cluster_arn" {
  description = "MSK cluster ARN — empty skips MSK IAM policy creation"
  type        = string
  default     = ""
}

variable "msk_topic_arn" {
  description = "MSK topic ARN (arn:aws:kafka:REGION:ACCOUNT:topic/CLUSTER/UUID/TOPIC) — empty skips MSK IAM"
  type        = string
  default     = ""
}

# -----------------------------------------------------------------------------
# Snowflake Sink Connector (Fargate) — Phase 4b
# -----------------------------------------------------------------------------

variable "sink_service_name" {
  description = "Fargate service name for the Snowflake sink connector"
  type        = string
  default     = "kc-sfsink-resonance-engine"
}

variable "sink_connector_name" {
  description = "Kafka Connect connector name (used in health check path)"
  type        = string
  default     = "snowflake_sink"
}

variable "sink_bootstrap_servers" {
  description = "MSK bootstrap servers for the sink connector (dev CDC cluster)"
  type        = string
  default     = "b-1.dev-managed-kafka-cdc.rk4es0.c11.kafka.us-east-1.amazonaws.com:9094,b-2.dev-managed-kafka-cdc.rk4es0.c11.kafka.us-east-1.amazonaws.com:9094,b-3.dev-managed-kafka-cdc.rk4es0.c11.kafka.us-east-1.amazonaws.com:9094"
}

variable "sink_ecr_image" {
  description = "Shared Kafka Connect Snowflake sink Docker image URI"
  type        = string
  default     = "086679231553.dkr.ecr.us-east-1.amazonaws.com/kafka-connect-sfsink:latest"
}

variable "sink_desired_task_count" {
  description = "Fargate desired task count — 0 to disable, 1 to enable"
  type        = number
  default     = 1

  validation {
    condition     = var.sink_desired_task_count == 0 || var.sink_bootstrap_servers != ""
    error_message = "sink_bootstrap_servers must be set when sink_desired_task_count > 0."
  }
}

variable "sink_snowflake_user" {
  description = "Snowflake service user for the sink connector"
  type        = string
  default     = "DEV_KAFKA_CONNECT_RESONANCE_ENGINE"
}

variable "sink_snowflake_role" {
  description = "Snowflake role for the sink connector"
  type        = string
  default     = "FANSIFTER_APP_REPORTING_DB_DEV_MMACHADO_SCHEMA_READWRITE"
}

variable "sink_snowflake_schema" {
  description = "Snowflake schema for the sink connector"
  type        = string
  default     = "DEV_MMACHADO"
}

variable "sink_snowflake_secret_names" {
  description = "Secrets Manager secret names for Snowflake sink connector credentials"
  type        = list(string)
  default     = ["SNOWFLAKE_PRIVATE_KEY", "SNOWFLAKE_PRIVATE_KEY_PASSPHRASE"]
}
