services:
  spaps-dev-api:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        SPAPS_SERVER_QUICKSTART_VERSION: ${SPAPS_SERVER_QUICKSTART_VERSION:-0.5.1}
    restart: unless-stopped
    ports:
      - "127.0.0.1:${SPAPS_LOCAL_PORT:-3301}:8000"
    environment:
      ENV: dev
      DATABASE_URL: postgresql+asyncpg://postgres:${SPAPS_LOCAL_POSTGRES_PASSWORD:?Set SPAPS_LOCAL_POSTGRES_PASSWORD}@spaps-dev-db:5432/spaps
      REDIS_URL: redis://spaps-dev-redis:6379/0
      SPAPS_LOCAL_MODE: "${SPAPS_LOCAL_MODE:-true}"
      JWT_SECRET: "${JWT_SECRET:-spaps_local_dev_jwt_secret}"
      REFRESH_TOKEN_SECRET: "${REFRESH_TOKEN_SECRET:-spaps_local_dev_refresh_secret}"
      SELF_SERVICE_PASSWORD: "${SELF_SERVICE_PASSWORD:-spaps_local_self_service_password}"
      ALEMBIC_RUN_ON_START_ROLE: primary
      LOG_LEVEL: DEBUG
      LOG_FORMAT: console
      AUTH_BASE_URL: "${SPAPS_AUTH_BASE_URL:-http://localhost:5173}"
      CORS_ALLOW_ORIGINS: "${CORS_ALLOW_ORIGINS:-http://localhost:3000,http://127.0.0.1:3000,http://localhost:3001,http://127.0.0.1:3001,http://localhost:5173,http://127.0.0.1:5173,http://localhost:30000,http://127.0.0.1:30000}"
      CORS_ALLOW_HEADERS: "${CORS_ALLOW_HEADERS:-Accept,Accept-Language,Authorization,Content-Language,Content-Type,X-API-Key,X-Request-ID,X-SPAPS-Signature,X-SPAPS-Use-Refresh-Cookie,X-Test-User}"
      LEGACY_API_KEY_AUTH_ENABLED: "${LEGACY_API_KEY_AUTH_ENABLED:-true}"
    depends_on:
      spaps-dev-db:
        condition: service_healthy
      spaps-dev-redis:
        condition: service_started
    healthcheck:
      test: ["CMD", "python", "-c", "import httpx; r = httpx.get('http://localhost:8000/health'); r.raise_for_status()"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 15s

  spaps-dev-db:
    image: ankane/pgvector:v0.5.1
    restart: unless-stopped
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: ${SPAPS_LOCAL_POSTGRES_PASSWORD:?Set SPAPS_LOCAL_POSTGRES_PASSWORD}
      POSTGRES_DB: spaps
    volumes:
      - spaps-dev-pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5

  spaps-dev-redis:
    image: redis:7-alpine
    restart: unless-stopped
    command: redis-server --appendonly yes
    volumes:
      - spaps-dev-redisdata:/data

volumes:
  spaps-dev-pgdata:
  spaps-dev-redisdata:
