services:
  postgres:
    image: postgres:16-alpine
    container_name: icp-postgres
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-icp_user}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-icp_local_dev_2024}
      POSTGRES_DB: ${POSTGRES_DB:-icp_tracker}
    ports:
      - "5433:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U icp_user -d icp_tracker"]
      interval: 5s
      timeout: 3s
      retries: 5

  auth:
    build: ./auth
    container_name: icp-auth
    ports:
      - "3004:3004"
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER:-icp_user}:${POSTGRES_PASSWORD:-icp_local_dev_2024}@postgres:5432/${POSTGRES_DB:-icp_tracker}
      APP_URL: ${APP_URL:-http://localhost:3004}
      AUTH_PORT: 3004
      BETTER_AUTH_SECRET: ${BETTER_AUTH_SECRET}
      MICROSOFT_CLIENT_ID: ${MICROSOFT_CLIENT_ID}
      MICROSOFT_CLIENT_SECRET: ${MICROSOFT_CLIENT_SECRET}
      MICROSOFT_TENANT_ID: ${MICROSOFT_TENANT_ID}
      AUTO_ADMIN_EMAILS: ${AUTO_ADMIN_EMAILS:-}
    depends_on:
      postgres:
        condition: service_healthy
    restart: unless-stopped

  web:
    build: .
    container_name: icp-web
    ports:
      - "5001:5001"
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER:-icp_user}:${POSTGRES_PASSWORD:-icp_local_dev_2024}@postgres:5432/${POSTGRES_DB:-icp_tracker}
      FLASK_SECRET_KEY: ${FLASK_SECRET_KEY:-dev-key-change-in-prod}
      APP_URL: ${APP_URL:-http://localhost:5001}
      ZOHO_CLIENT_ID: ${ZOHO_CLIENT_ID:-}
      ZOHO_CLIENT_SECRET: ${ZOHO_CLIENT_SECRET:-}
      ZOHO_REFRESH_TOKEN: ${ZOHO_REFRESH_TOKEN:-}
      ZOHO_API_DOMAIN: ${ZOHO_API_DOMAIN:-https://www.zohoapis.eu}
      ZOHO_ACCOUNTS_URL: ${ZOHO_ACCOUNTS_URL:-https://accounts.zoho.eu}
    depends_on:
      postgres:
        condition: service_healthy
      auth:
        condition: service_started
    restart: unless-stopped

volumes:
  pgdata:
