###############################################################################
# Greenfield MDP — Production Environment — Root Module
# Wires all child modules together for the production deployment.
###############################################################################

# =============================================================================
# Phase 0 / Day 1 — Networking
# =============================================================================

module "networking" {
  source = "../../modules/networking"

  location    = var.location
  environment = var.environment
  project     = var.project

  # VNet CIDRs
  vnet_cidr                     = var.vnet_cidr
  dbx_host_subnet_cidr          = var.dbx_host_subnet_cidr
  dbx_container_subnet_cidr     = var.dbx_container_subnet_cidr
  private_endpoints_subnet_cidr = var.private_endpoints_subnet_cidr
  transit_vnet_cidr             = var.transit_vnet_cidr
  transit_subnet_cidr           = var.transit_subnet_cidr

  # Hub peering (set in terraform.tfvars when Greenfield hub VNet is available)
  hub_vnet_id = var.hub_vnet_id

  tags = var.tags
}

# =============================================================================
# Phase 0 / Day 3–5 — Storage (ADLS Gen2)
# Uncomment when modules/storage is ready.
# =============================================================================

# module "storage" {
#   source = "../../modules/storage"
#
#   location            = var.location
#   environment         = var.environment
#   project             = var.project
#   resource_group_name = module.networking.rg_storage_name
#   subnet_pe_id        = module.networking.subnet_private_endpoints_id
#   dns_zone_dfs_id     = module.networking.dns_zone_dfs_id
#   replication_type    = var.adls_replication_type
#   tags                = var.tags
# }

# =============================================================================
# Phase 0 / Day 3 — Key Vault
# Uncomment when modules/keyvault is ready.
# =============================================================================

# module "keyvault" {
#   source = "../../modules/keyvault"
#
#   location            = var.location
#   environment         = var.environment
#   project             = var.project
#   resource_group_name = module.networking.rg_keyvault_name
#   subnet_pe_id        = module.networking.subnet_private_endpoints_id
#   dns_zone_vault_id   = module.networking.dns_zone_vault_id
#   tags                = var.tags
# }

# =============================================================================
# Phase 0 / Day 4–6 — Identity (Managed Identities, Role Assignments)
# Uncomment when modules/identity is ready.
# =============================================================================

# module "identity" {
#   source = "../../modules/identity"
#
#   location             = var.location
#   environment          = var.environment
#   project              = var.project
#   rg_databricks_name   = module.networking.rg_databricks_name
#   rg_storage_name      = module.networking.rg_storage_name
#   rg_governance_name   = module.networking.rg_governance_name
#   storage_account_id   = module.storage.adls_id
#   tags                 = var.tags
# }

# =============================================================================
# Phase 0 / Day 6–8 — Databricks Workspace
# Uncomment when modules/databricks-workspace is ready.
# =============================================================================

# module "databricks_workspace" {
#   source = "../../modules/databricks-workspace"
#
#   location                  = var.location
#   environment               = var.environment
#   project                   = var.project
#   resource_group_name       = module.networking.rg_databricks_name
#   vnet_id                   = module.networking.vnet_main_id
#   subnet_host_id            = module.networking.subnet_dbx_host_id
#   subnet_host_name          = module.networking.subnet_dbx_host_name
#   subnet_container_id       = module.networking.subnet_dbx_container_id
#   subnet_container_name     = module.networking.subnet_dbx_container_name
#   subnet_pe_id              = module.networking.subnet_private_endpoints_id
#   subnet_transit_id         = module.networking.subnet_transit_id
#   nsg_id                    = module.networking.nsg_dbx_id
#   dns_zone_databricks_id    = module.networking.dns_zone_databricks_id
#   dns_zone_databricks_name  = module.networking.dns_zone_databricks_name
#   rg_network_name           = module.networking.rg_network_name
#   vnet_transit_id           = module.networking.vnet_transit_id
#   tags                      = var.tags
# }

# =============================================================================
# Phase 0 / Day 11–13 — Unity Catalog
# Uncomment when modules/unity-catalog is ready.
# =============================================================================

# module "unity_catalog" {
#   source = "../../modules/unity-catalog"
#
#   providers = {
#     databricks.account   = databricks.account
#     databricks.workspace = databricks.workspace
#   }
#
#   location             = var.location
#   environment          = var.environment
#   project              = var.project
#   databricks_account_id = var.databricks_account_id
#   workspace_id         = module.databricks_workspace.workspace_id
#   storage_account_name = module.storage.adls_name
#   catalog_names        = var.uc_catalog_names
#   schemas              = var.uc_schemas
#   tags                 = var.tags
# }

# =============================================================================
# Phase 0 / Day 3 — Monitoring (Log Analytics, Diagnostic Settings)
# Uncomment when modules/monitoring is ready.
# =============================================================================

# module "monitoring" {
#   source = "../../modules/monitoring"
#
#   location            = var.location
#   environment         = var.environment
#   project             = var.project
#   resource_group_name = module.networking.rg_monitoring_name
#   tags                = var.tags
# }
