services:
  admin:
    build:
      context: .
      dockerfile: apps/admin/Dockerfile
      args:
        BETTER_AUTH_SECRET: "${BETTER_AUTH_SECRET}"
        BETTER_AUTH_URL: "${BETTER_AUTH_URL:-https://innungsapp.com}"
        BETTER_AUTH_BASE_URL: "${BETTER_AUTH_URL:-https://innungsapp.com}"
        NEXT_PUBLIC_APP_URL: "${NEXT_PUBLIC_APP_URL:-https://innungsapp.com}"
    container_name: innungsapp-admin
    restart: unless-stopped
    ports:
      - "3010:3000"
    environment:
      # Database — SQLite file inside the named volume
      DATABASE_URL: "file:/app/data/prod.db"

      # Auth — CHANGE THESE in production!
      BETTER_AUTH_SECRET: "${BETTER_AUTH_SECRET}"
      BETTER_AUTH_URL: "${BETTER_AUTH_URL:-https://yourdomain.com}"
      BETTER_AUTH_BASE_URL: "${BETTER_AUTH_URL:-https://yourdomain.com}"

      # Email (SMTP)
      EMAIL_FROM: "${EMAIL_FROM:-noreply@innungsapp.de}"
      SMTP_HOST: "${SMTP_HOST}"
      SMTP_PORT: "${SMTP_PORT:-587}"
      SMTP_SECURE: "${SMTP_SECURE:-false}"
      SMTP_USER: "${SMTP_USER}"
      SMTP_PASS: "${SMTP_PASS}"

      # Public URLs
      NEXT_PUBLIC_APP_URL: "${NEXT_PUBLIC_APP_URL:-https://yourdomain.com}"
      NEXT_PUBLIC_POSTHOG_KEY: "${NEXT_PUBLIC_POSTHOG_KEY:-}"
      NEXT_PUBLIC_POSTHOG_HOST: "${NEXT_PUBLIC_POSTHOG_HOST:-https://us.i.posthog.com}"

      # File uploads
      UPLOAD_DIR: "/app/uploads"
      UPLOAD_MAX_SIZE_MB: "${UPLOAD_MAX_SIZE_MB:-10}"

      # Node
      NODE_ENV: "production"
    volumes:
      # SQLite database — persists across restarts
      - db_data:/app/data
      # Uploaded files — persists across restarts
      - uploads_data:/app/uploads
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://localhost:3000/api/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

volumes:
  db_data:
  uploads_data:
