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

Moved from the original aws_tf_mcp.dependencies module.
"""

from __future__ import annotations

# Layer assignments for topological ordering
MODULE_LAYERS: dict[str, int] = {
    "vpc": 1,
    "ecr-repository": 1,
    "ecs-cluster": 2,
    "eks-cluster": 2,
    "ec2-asg": 3,
    "ecs-service": 3,
    "eks-node-group": 3,
    "eks-fargate-profile": 3,
    "lambda-function": 3,
    "eks-irsa": 4,
}

MODULE_DESCRIPTIONS: dict[str, str] = {
    "vpc": "Multi-AZ VPC with public/private/database subnets, NAT Gateways, flow logs",
    "eks-cluster": "EKS control plane with OIDC, secrets encryption, logging, addons",
    "eks-node-group": "Managed EKS node group with launch template, scaling, taints/labels",
    "eks-fargate-profile": "EKS Fargate profile for serverless Kubernetes pods",
    "eks-irsa": "IAM Roles for Service Accounts (IRSA) or Pod Identity",
    "ecs-cluster": "ECS cluster with Fargate/EC2 capacity providers, Container Insights",
    "ecs-service": "ECS service + task definition + IAM roles + auto-scaling",
    "ecr-repository": "ECR repo with lifecycle policies, scanning, cross-account access",
    "ec2-asg": "EC2 Auto Scaling Group with launch template, mixed instances, ALB integration",
    "lambda-function": "Lambda function with IAM role, VPC config, layers, log group",
}

DIRECT_DEPENDENCIES: dict[str, list[str]] = {
    "vpc": [],
    "ecr-repository": [],
    "ecs-cluster": [],
    "eks-cluster": ["vpc"],
    "eks-node-group": ["eks-cluster", "vpc"],
    "eks-fargate-profile": ["eks-cluster", "vpc"],
    "eks-irsa": ["eks-cluster"],
    "ecs-service": ["ecs-cluster", "vpc"],
    "ec2-asg": ["vpc"],
    "lambda-function": ["vpc"],
}

WIRING_MAP: dict[tuple[str, str], dict[str, str]] = {
    ("vpc", "eks-cluster"): {
        "vpc_id": "vpc_id",
        "private_subnet_ids": "subnet_ids",
    },
    ("vpc", "eks-node-group"): {
        "private_subnet_ids": "subnet_ids",
    },
    ("vpc", "eks-fargate-profile"): {
        "private_subnet_ids": "subnet_ids",
    },
    ("vpc", "ec2-asg"): {
        "vpc_id": "vpc_id",
        "private_subnet_ids": "subnet_ids",
    },
    ("vpc", "ecs-service"): {
        "vpc_id": "vpc_id",
        "private_subnet_ids": "subnet_ids",
    },
    ("vpc", "lambda-function"): {
        "private_subnet_ids": "vpc_config.subnet_ids",
    },
    ("eks-cluster", "eks-node-group"): {
        "cluster_name": "cluster_name",
    },
    ("eks-cluster", "eks-fargate-profile"): {
        "cluster_name": "cluster_name",
    },
    ("eks-cluster", "eks-irsa"): {
        "oidc_provider_arn": "oidc_provider_arn",
        "oidc_provider_url": "oidc_provider_url",
        "cluster_name": "cluster_name",
    },
    ("ecs-cluster", "ecs-service"): {
        "cluster_arn": "cluster_arn",
        "cluster_name": "cluster_name",
    },
}

PROVIDER_CONFIG = {
    "source": "hashicorp/aws",
    "version_constraint": "~> 5.0",
    "provider_name": "aws",
    "provider_block": 'provider "aws" {\n  region = var.region\n}',
    "region_variable": "region",
    "region_default": "us-east-1",
    "tags_variable": "tags",
    "tags_type": "map(string)",
}

IDENTITY_DEFAULTS: dict[str, dict[str, str]] = {
    "vpc": {
        "cidr_block": '"10.0.0.0/16"',
        "azs": "local.azs",
    },
    "eks-cluster": {
        "cluster_version": '"1.31"',
    },
    "eks-node-group": {
        "node_group_name": '"general"',
        "cluster_version": '"1.31"',
    },
    "eks-fargate-profile": {
        "profile_name": '"default"',
    },
    "eks-irsa": {
        "role_name_suffix": '"app"',
        "service_account_namespace": '"default"',
        "service_account_name": '"app"',
    },
    "ecs-cluster": {},
    "ecs-service": {
        "container_image": '"nginx:alpine"',
    },
    "ecr-repository": {},
    "ec2-asg": {
        "asg_name": '"web"',
    },
    "lambda-function": {
        "function_name": '"worker"',
        "runtime": '"python3.12"',
        "handler": '"main.handler"',
    },
}

KEY_OUTPUTS: dict[str, list[str]] = {
    "vpc": ["vpc_id"],
    "eks-cluster": ["cluster_name", "cluster_endpoint"],
    "eks-node-group": ["node_group_name"],
    "eks-fargate-profile": ["fargate_profile_name"],
    "eks-irsa": ["role_arn"],
    "ecs-cluster": ["cluster_name"],
    "ecs-service": ["service_name"],
    "ecr-repository": ["repository_url"],
    "ec2-asg": ["asg_name"],
    "lambda-function": ["function_arn"],
}

SHORT_NAMES: dict[str, str] = {
    "vpc": "vpc",
    "eks-cluster": "eks",
    "eks-node-group": "node_group",
    "eks-fargate-profile": "fargate",
    "eks-irsa": "irsa",
    "ecs-cluster": "ecs",
    "ecs-service": "service",
    "ecr-repository": "ecr",
    "ec2-asg": "asg",
    "lambda-function": "lambda",
}
