################################################################################
# Module: redis
# Outputs
################################################################################

output "primary_endpoint" {
  description = "Primary endpoint hostname for write operations. Use to construct REDIS_URL."
  value       = aws_elasticache_replication_group.main.primary_endpoint_address
}

output "reader_endpoint" {
  description = "Reader endpoint for read operations (load-balanced across replicas)."
  value       = aws_elasticache_replication_group.main.reader_endpoint_address
}

output "port" {
  description = "Port the Redis replication group listens on (always 6379)."
  value       = aws_elasticache_replication_group.main.port
}

output "replication_group_id" {
  description = "ID of the ElastiCache replication group."
  value       = aws_elasticache_replication_group.main.replication_group_id
}

output "security_group_id" {
  description = "Security group ID attached to the replication group. Use to add further ingress rules."
  value       = aws_security_group.redis.id
}

output "redis_url" {
  description = "Constructed REDIS_URL using the primary endpoint. Includes rediss:// (TLS) scheme when transit encryption is enabled."
  value       = var.transit_encryption_enabled ? "rediss://${aws_elasticache_replication_group.main.primary_endpoint_address}:${aws_elasticache_replication_group.main.port}" : "redis://${aws_elasticache_replication_group.main.primary_endpoint_address}:${aws_elasticache_replication_group.main.port}"
}
