# LOCAL NETWORK test stack — the full production setup over plain HTTP, no domain.
# Everything (frontend + backend + Mongo + storage) runs behind Caddy on port 80.
#
# Zero config on the server itself:
#   docker compose -f docker-compose.local.yml up -d --build
#   -> http://localhost/           (from the server)
#   -> http://<server-lan-ip>/     (from other devices on the network)
#
# To make uploaded-image URLs resolve from OTHER devices, set SERVER_URL to the
# server's LAN address before starting, e.g.:
#   SERVER_URL=http://192.168.1.87 docker compose -f docker-compose.local.yml up -d --build
#
# Credentials here are fixed local-dev values — do NOT use this file in production
# (use docker-compose.prod.yml).

services:
  mongo:
    image: mongo:7
    container_name: foz-fc-mongo-local
    restart: unless-stopped
    environment:
      MONGO_INITDB_ROOT_USERNAME: fozfc
      MONGO_INITDB_ROOT_PASSWORD: localdevpass
    volumes:
      - mongo_data_local:/data/db
    healthcheck:
      test:
        [
          "CMD", "mongosh", "--quiet",
          "-u", "fozfc", "-p", "localdevpass",
          "--authenticationDatabase", "admin",
          "--eval", "db.adminCommand('ping')"
        ]
      interval: 10s
      timeout: 5s
      retries: 5

  backend:
    build: ./backend
    container_name: foz-fc-backend-local
    restart: unless-stopped
    depends_on:
      mongo:
        condition: service_healthy
    environment:
      PORT: 4000
      MONGODB_URI: mongodb://fozfc:localdevpass@mongo:27017/?authSource=admin
      MONGODB_DB: foz_fc
      JWT_SECRET: local-dev-jwt-secret-not-for-production-0123456789
      JWT_TTL_SECONDS: 2592000
      CORS_ORIGINS: ${SERVER_URL:-http://localhost}
      FIREBASE_PROJECT_ID: fc-foz-53e0a
      # Absolute base for upload URLs. Defaults to localhost; override with SERVER_URL
      # (e.g. http://192.168.1.87) so images load from other LAN devices.
      PUBLIC_BASE_URL: ${SERVER_URL:-http://localhost}
      ALLOW_UNVERIFIED_GOOGLE: "false"
      SEED_ADMIN_EMAIL: admin@foz.pt
      SEED_ADMIN_PASSWORD: admin123
      ASPNETCORE_ENVIRONMENT: Production
    volumes:
      - uploads_data_local:/app/uploads
    expose:
      - "4000"

  frontend:
    build:
      context: ./frontend
      args:
        VITE_API_BASE_URL: /api
        VITE_FIREBASE_API_KEY: AIzaSyA_kaV_aEvQto8QlF90f5wR2VTNnDpKCBg
        VITE_FIREBASE_AUTH_DOMAIN: fc-foz-53e0a.firebaseapp.com
        VITE_FIREBASE_PROJECT_ID: fc-foz-53e0a
        VITE_FIREBASE_STORAGE_BUCKET: fc-foz-53e0a.firebasestorage.app
        VITE_FIREBASE_MESSAGING_SENDER_ID: "129251568307"
        VITE_FIREBASE_APP_ID: 1:129251568307:web:1c0bf6d14faa4464e75ec6
        VITE_GOOGLE_AUTH_CLIENT_ID: 129251568307-t2vegovea41nurm3osmpiucdt8nv0g9q.apps.googleusercontent.com
        VITE_RECAPTCHA_SITE_KEY: 6Lek7assAAAAADBQ8Ex9gIjmZMGiiLvVc0Dt1BCK
        # Empty => the ZeroZero feeds are served by THIS backend at /api/*-feed (same origin).
        VITE_ZEROZERO_PROXY_BASE_URL: ""
        VITE_CTT_TRACKING_WORKER_URL: https://fc-foz-ctt-tracking.manuel-pereira-silva28.workers.dev
        VITE_CREATE_CHECKOUT_SESSION_URL: https://fc-foz-stripe.manuel-pereira-silva28.workers.dev/create-checkout-session
    container_name: foz-fc-frontend-local
    restart: unless-stopped
    expose:
      - "80"

  caddy:
    image: caddy:2
    container_name: foz-fc-caddy-local
    restart: unless-stopped
    depends_on:
      - backend
      - frontend
    ports:
      - "${HTTP_PORT:-80}:80"
    volumes:
      - ./Caddyfile.local:/etc/caddy/Caddyfile:ro
      - caddy_data_local:/data
      - caddy_config_local:/config

volumes:
  mongo_data_local:
  uploads_data_local:
  caddy_data_local:
  caddy_config_local:
