output "url" {
  description = "URL of the environment"
  value       = "https://${var.environment}-${local.service_label}.theorchard.io"
}

output "service_label" {
  description = "Full service name (e.g. 'ows-coda' or 'ows-coda-pr-42'). Use with AWS CLI: aws ecs list-tasks --cluster <cluster> --service-name <this>"
  value       = local.service_label
}

output "db_name" {
  description = "Database name on the RDS cluster"
  value       = local.db_name
}

output "fargate_security_group_id" {
  description = "Security group of the Fargate task"
  value       = module.ows_coda_fargate_environment.fargate_security_group_id
}

output "fargate_task_iam_role_name" {
  description = "IAM role name of the Fargate task (for debugging permission issues)"
  value       = module.ows_coda_fargate_environment.fargate_task_iam_role_name
}

output "rds_cluster_endpoint" {
  description = "RDS cluster endpoint (main environment only)"
  value       = local.is_ephemeral ? "" : module.ows_coda_rds[0].rds_cluster_endpoint
}

output "redis_primary_endpoint_address" {
  description = "Redis primary endpoint (main environment only)"
  value       = local.is_ephemeral ? "" : module.ows_coda_chatbot_cache[0].redis_primary_endpoint_address
}

output "s3_bucket_name" {
  description = "S3 uploads bucket name"
  value       = local.s3_bucket
}

output "search_url" {
  description = "Internal URL of the ows-coda-search service (empty for ephemeral envs)"
  value       = local.is_ephemeral ? "" : "https://${var.environment}-${local.search_service_name}.theorchard.io"
}

output "search_snapshots_bucket" {
  description = "S3 bucket for search index snapshots (main environment only)"
  value       = local.is_ephemeral ? "" : module.s3_ows_coda_search_snapshots[0].s3_bucket_name_output
}

output "search_ecs_cluster" {
  description = "ECS cluster name for the GPU search service (main environment only)"
  value       = local.is_ephemeral ? "" : aws_ecs_cluster.search[0].name
}

output "search_alb_dns_name" {
  description = "ALB DNS name for the search service (main environment only)"
  value       = local.is_ephemeral ? "" : aws_lb.search[0].dns_name
}

output "search_task_role_arn" {
  description = "IAM role ARN of the search ECS task (main environment only)"
  value       = local.is_ephemeral ? "" : aws_iam_role.search_task[0].arn
}

output "runner_url" {
  description = "Internal URL of the ows-coda-runner service (empty for ephemeral envs)"
  value       = local.is_ephemeral ? "" : "https://${var.environment}-${local.runner_service_name}.theorchard.io"
}

output "runner_cache_bucket" {
  description = "S3 bucket for runner pipeline cache (main environment only)"
  value       = local.is_ephemeral ? "" : module.s3_ows_coda_runner_cache[0].s3_bucket_name_output
}

output "runner_ecs_cluster" {
  description = "ECS cluster name for the runner service (main environment only)"
  value       = local.is_ephemeral ? "" : module.runner_fargate[0].fargate_cluster_name
}

output "runner_alb_dns_name" {
  description = "Internal ALB DNS name for the runner service (main environment only)"
  value       = local.is_ephemeral ? "" : module.runner_fargate[0].fargate_load_balancer_dns_name
}

output "runner_task_role_arn" {
  description = "IAM role ARN of the runner ECS task (main environment only)"
  value       = local.is_ephemeral ? "" : module.runner_fargate[0].fargate_task_iam_role_arn
}

output "langfuse_url" {
  description = "Langfuse dashboard URL (VPN-only, main environment only)"
  value       = local.create_langfuse ? "https://${var.environment}-${local.langfuse_web_service_name}.theorchard.io" : ""
}

output "api_gateway_url" {
  description = "API Gateway invoke URL (main environment only)"
  value       = local.create_api_gateway ? aws_apigatewayv2_api.coda[0].api_endpoint : ""
}

output "api_gateway_domain" {
  description = "API Gateway custom domain (main environment only)"
  value       = local.create_api_gateway ? "https://${var.api_gateway_domain}" : ""
}
