# Azure-specific outputs for integration with Kubernetes and services

output "subscription_id" {
  description = "Azure subscription ID"
  value       = data.azurerm_subscription.current.subscription_id
  sensitive   = true
}

output "tenant_id" {
  description = "Azure tenant ID"
  value       = data.azurerm_client_config.current.tenant_id
  sensitive   = true
}

output "resource_group_name" {
  description = "Main resource group name"
  value       = azurerm_resource_group.main.name
}

output "storage_account_name" {
  description = "Application data storage account name"
  value       = azurerm_storage_account.app_data.name
}

output "storage_account_primary_key" {
  description = "Storage account primary access key"
  value       = azurerm_storage_account.app_data.primary_access_key
  sensitive   = true
}

output "key_vault_name" {
  description = "Key Vault name"
  value       = azurerm_key_vault.main.name
}

output "key_vault_uri" {
  description = "Key Vault URI"
  value       = azurerm_key_vault.main.vault_uri
}

# CDN Outputs
output "cdn_storage_account_name" {
  description = "CDN storage account name"
  value       = azurerm_storage_account.cdn_images.name
}

output "cdn_blob_url" {
  description = "CDN blob storage URL"
  value       = "https://${azurerm_storage_account.cdn_images.name}.blob.core.windows.net/${azurerm_storage_container.cdn_images.name}/"
}

output "cdn_endpoint_url" {
  description = "CDN endpoint URL"
  value       = "https://${azurerm_cdn_endpoint.cdn_images.host_name}/${azurerm_storage_container.cdn_images.name}/"
}

# Database Outputs
output "database_fqdn" {
  description = "Database fully qualified domain name"
  value       = try(azurerm_postgresql_flexible_server.main[0].fqdn, null)
  sensitive   = true
}

output "database_name" {
  description = "Database name"
  value       = try(azurerm_postgresql_flexible_server_database.main[0].name, null)
}

# AKS Outputs (if created)
output "aks_cluster_name" {
  description = "AKS cluster name"
  value       = try(azurerm_kubernetes_cluster.main[0].name, null)
}

output "aks_fqdn" {
  description = "AKS cluster FQDN"
  value       = try(azurerm_kubernetes_cluster.main[0].fqdn, null)
}

output "log_analytics_workspace_id" {
  description = "Log Analytics Workspace ID"
  value       = try(azurerm_log_analytics_workspace.main[0].workspace_id, null)
}

# Export all outputs to environment variables file
output "env_file_snippet" {
  description = "Environment variables snippet for .env file"
  value = <<-EOT
    # Azure Infrastructure Outputs (auto-generated)
    AZURE_SUBSCRIPTION_ID="${data.azurerm_subscription.current.subscription_id}"
    AZURE_TENANT_ID="${data.azurerm_client_config.current.tenant_id}"
    AZURE_RESOURCE_GROUP="${azurerm_resource_group.main.name}"
    AZURE_STORAGE_ACCOUNT="${azurerm_storage_account.app_data.name}"
    AZURE_KEY_VAULT_NAME="${azurerm_key_vault.main.name}"
    AZURE_KEY_VAULT_URI="${azurerm_key_vault.main.vault_uri}"
    CDN_STORAGE_ACCOUNT="${azurerm_storage_account.cdn_images.name}"
    CDN_BASE_URL_BLOB="https://${azurerm_storage_account.cdn_images.name}.blob.core.windows.net/${azurerm_storage_container.cdn_images.name}/"
    CDN_BASE_URL_CDN="https://${azurerm_cdn_endpoint.cdn_images.host_name}/${azurerm_storage_container.cdn_images.name}/"
  EOT
  sensitive = true
}

