"""Azure module metadata: layers, dependencies, wiring, descriptions."""

from __future__ import annotations

# Layer assignments for topological ordering
MODULE_LAYERS: dict[str, int] = {
    "vnet": 1,
    "container-registry": 1,
    "aks-cluster": 2,
    "container-app-environment": 2,
    "aks-node-pool": 3,
    "aks-workload-identity": 3,
    "container-app": 3,
    "function-app": 3,
    "vm-scale-set": 3,
}

MODULE_DESCRIPTIONS: dict[str, str] = {
    "vnet": "VNet with public/private/database subnets, NSGs, NAT Gateway, flow logs",
    "aks-cluster": "AKS control plane with system node pool, RBAC, monitoring, workload identity",
    "aks-node-pool": "AKS user node pool with autoscaling, spot instances, taints/labels",
    "aks-workload-identity": "Managed identity with federated credential for Kubernetes workload identity",
    "container-registry": "ACR with SKU tiers, geo-replication, retention, network rules, encryption",
    "container-app-environment": "Container Apps Environment with VNet integration, Log Analytics",
    "container-app": "Container App with containers, ingress, scaling rules, registries, secrets",
    "function-app": "Function App with App Service Plan, Storage, Application Insights, VNet integration",
    "vm-scale-set": "Linux VMSS with autoscaling, spot VMs, availability zones, managed identity",
}

DIRECT_DEPENDENCIES: dict[str, list[str]] = {
    "vnet": [],
    "container-registry": [],
    "aks-cluster": ["vnet"],
    "container-app-environment": [],
    "aks-node-pool": ["aks-cluster", "vnet"],
    "aks-workload-identity": ["aks-cluster"],
    "container-app": ["container-app-environment"],
    "function-app": ["vnet"],
    "vm-scale-set": ["vnet"],
}

# Wiring: (source_module, target_module) -> {source_output: target_input}
# Only includes direct output-to-input matches (same type).
# vnet -> subnet_id wirings are omitted because private_subnet_ids is a list
# and subnet_id expects a string — users must index: module.vnet.private_subnet_ids[0]
WIRING_MAP: dict[tuple[str, str], dict[str, str]] = {
    ("aks-cluster", "aks-node-pool"): {
        "cluster_id": "cluster_id",
    },
    ("aks-cluster", "aks-workload-identity"): {
        "oidc_issuer_url": "oidc_issuer_url",
    },
    ("container-app-environment", "container-app"): {
        "environment_id": "container_app_environment_id",
    },
}

PROVIDER_CONFIG = {
    "source": "hashicorp/azurerm",
    "version_constraint": "~> 4.0",
    "provider_name": "azurerm",
    "provider_block": 'provider "azurerm" {\n  features {}\n}',
    "region_variable": "location",
    "region_default": "eastus",
    "tags_variable": "tags",
    "tags_type": "map(string)",
}

IDENTITY_DEFAULTS: dict[str, dict[str, str]] = {
    "vnet": {
        "address_space": '"10.0.0.0/16"',
    },
    "aks-cluster": {
        "kubernetes_version": '"1.31"',
    },
    "aks-node-pool": {
        "node_pool_name": '"general"',
    },
    "aks-workload-identity": {
        "identity_name": '"app"',
        "namespace": '"default"',
        "service_account_name": '"app"',
    },
    "container-registry": {},
    "container-app-environment": {},
    "container-app": {
        "container_app_name": '"app"',
    },
    "function-app": {
        "function_name": '"worker"',
        "runtime_stack": '"python"',
        "runtime_version": '"3.11"',
    },
    "vm-scale-set": {
        "vmss_name": '"web"',
    },
}

KEY_OUTPUTS: dict[str, list[str]] = {
    "vnet": ["vnet_id"],
    "aks-cluster": ["cluster_name", "cluster_id"],
    "aks-node-pool": ["node_pool_name"],
    "aks-workload-identity": ["identity_client_id"],
    "container-registry": ["login_server"],
    "container-app-environment": ["environment_id"],
    "container-app": ["container_app_name", "fqdn"],
    "function-app": ["function_app_name", "default_hostname"],
    "vm-scale-set": ["vmss_id"],
}

SHORT_NAMES: dict[str, str] = {
    "vnet": "vnet",
    "aks-cluster": "aks",
    "aks-node-pool": "node_pool",
    "aks-workload-identity": "workload_id",
    "container-registry": "acr",
    "container-app-environment": "cae",
    "container-app": "app",
    "function-app": "func",
    "vm-scale-set": "vmss",
}
