services:
  php-apache:
    build: ./docker/php-apache
    container_name: php-apache
    ports:
      - "8080:80"
    volumes:
      - .:/var/www/html
      - vendor:/var/www/html/vendor
    environment:
      - TAXCORE_SERVICE_URL=http://taxcore-service:3001
    depends_on:
      - postgres
      - redis
      - taxcore-service
    networks:
      - taf-network

  postgres:
    build:
      context: ./docker/postgres
    container_name: postgres
    environment:
      POSTGRES_USER: taf
      POSTGRES_PASSWORD: TAF123*
      POSTGRES_DB: frcsdb
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    networks:
      - taf-network

  redis:
    image: redis:7
    container_name: redis
    ports:
      - "6379:6379"
    networks:
      - taf-network

  taxcore-service:
    build:
      context: .
      dockerfile: ./docker/taxcore-service/Dockerfile
    container_name: taxcore-service
    ports:
      - "3001:3001"
    volumes:
      - ./websocket-server:/usr/src/app
      - taxcore-node-modules:/usr/src/app/node_modules # Prevent host from overriding installed modules
      - ./FRCS_Certs_Install:/usr/src/app/certs:ro
      - ./logs:/usr/src/logs
    environment:
      - TAXCORE_LOG_DIR=/usr/src/logs
      - TAXCORE_SERVICE_PORT=3001
      - TAXCORE_ORG_ID=${TAXCORE_ORG_ID:-0194a8b2-1234-7123-8123-123456789abc}
      - TAXCORE_TAX_URL=${TAXCORE_TAX_URL:-https://api.sandbox.vms.frcs.org.fj/api}
      - TAXCORE_VSDC_URL=${TAXCORE_VSDC_URL:-http://devesdc.sandbox.vms.frcs.org.fj:8888/20f351f3-9b39-4c63-b9e0-d8a00b6e93fb/api}
      - TAXCORE_PFX_PATH=/usr/src/app/certs/${TAXCORE_PFX_FILE:-LK2VRSH4-DeveloperAuthenticationCertificate.pfx}
      - TAXCORE_PFX_PASSWORD=${TAXCORE_PFX_PASSWORD:-2CBP6HMW}
      - TAXCORE_PIN_JSON=${TAXCORE_PIN_JSON:-3840}
      - TAXCORE_DEBUG=${TAXCORE_DEBUG:-true}
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3001/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    networks:
      - taf-network

volumes:
  pgdata:
  vendor: # Persist PHP composer dependencies
  taxcore-node-modules: # Persist node_modules for taxcore-service

networks:
  taf-network:
    driver: bridge
#   websocket-server:
#     build: ./websocket-server
#     container_name: websocket-server
#     working_dir: /usr/src/app
#     volumes:
#       - ./websocket-server:/usr/src/app
#     ports:
#       - "8081:8081"
#     environment:
#       - PORT=8081
#     depends_on:
#       - redis
#       - postgres

# optional Installation server (commented out for now)
# installation-server:
#   build: ./docker/installation-server
#   container_name: installation-server
#   working_dir: /usr/src/app
#   volumes:
#     - ./Installation:/usr/src/app
#   ports:
#     - "3002:3002"
#   environment:
#     - PORT=3002
#   depends_on:
#     - redis
#     - postgres
