"""Demo data for infra-diagram — sample IaC files."""

from __future__ import annotations

DEMO_TERRAFORM = '''# main.tf — AWS infrastructure
resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
  tags       = { Name = "main-vpc" }
}

resource "aws_subnet" "public" {
  vpc_id     = aws_vpc.main.id
  cidr_block = "10.0.1.0/24"
}

resource "aws_subnet" "private" {
  vpc_id     = aws_vpc.main.id
  cidr_block = "10.0.2.0/24"
}

resource "aws_internet_gateway" "gw" {
  vpc_id = aws_vpc.main.id
}

resource "aws_security_group" "web" {
  vpc_id = aws_vpc.main.id
  name   = "web-sg"
}

resource "aws_lb" "web" {
  name               = "web-alb"
  internal           = false
  load_balancer_type = "application"
  subnets            = [aws_subnet.public.id]
}

resource "aws_ecs_cluster" "main" {
  name = "app-cluster"
}

resource "aws_ecs_service" "api" {
  name            = "api-service"
  cluster         = aws_ecs_cluster.main.id
  task_definition = aws_ecs_task_definition.api.arn
}

resource "aws_ecs_task_definition" "api" {
  family = "api-task"
}

resource "aws_rds_instance" "db" {
  engine         = "postgres"
  instance_class = "db.t3.medium"
}

resource "aws_elasticache_cluster" "cache" {
  engine = "redis"
}

resource "aws_s3_bucket" "assets" {
  bucket = "app-assets"
}

resource "aws_cloudfront_distribution" "cdn" {
  enabled = true
}

resource "aws_sqs_queue" "tasks" {
  name = "task-queue"
}

resource "aws_lambda_function" "worker" {
  function_name = "task-worker"
  handler       = "index.handler"
  runtime       = "nodejs18.x"
}

resource "aws_cloudwatch_log_group" "app" {
  name = "/app/logs"
}
'''

DEMO_KUBERNETES = '''apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
  namespace: production
spec:
  replicas: 3
  template:
    spec:
      containers:
      - name: app
        image: myapp:latest
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: web-service
  namespace: production
spec:
  type: LoadBalancer
  selector:
    app: web-app
  ports:
  - port: 80
    targetPort: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web-ingress
  namespace: production
spec:
  rules:
  - host: app.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: web-service
            port:
              number: 80
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: database
  namespace: production
spec:
  replicas: 1
  template:
    spec:
      containers:
      - name: postgres
        image: postgres:15
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
  namespace: production
data:
  APP_ENV: production
---
apiVersion: v1
kind: Secret
metadata:
  name: db-credentials
  namespace: production
type: Opaque
'''

DEMO_COMPOSE = '''version: "3.8"
services:
  web:
    build: ./web
    ports:
      - "80:8080"
    depends_on:
      - api
      - redis
    networks:
      - frontend
      - backend
    environment:
      - API_URL=http://api:3000

  api:
    image: node:18-alpine
    ports:
      - "3000:3000"
    depends_on:
      - postgres
      - redis
    networks:
      - backend
    volumes:
      - app-data:/data

  postgres:
    image: postgres:15
    environment:
      POSTGRES_DB: myapp
    volumes:
      - pg-data:/var/lib/postgresql/data
    networks:
      - backend

  redis:
    image: redis:7-alpine
    networks:
      - backend

  nginx:
    image: nginx:alpine
    ports:
      - "443:443"
    depends_on:
      - web
    networks:
      - frontend

volumes:
  pg-data:
  app-data:

networks:
  frontend:
  backend:
'''

DEMOS = {
    "terraform": ("main.tf", DEMO_TERRAFORM),
    "kubernetes": ("k8s-manifests.yaml", DEMO_KUBERNETES),
    "compose": ("docker-compose.yml", DEMO_COMPOSE),
}
