version: '3.8'

services:
  # Backend PHP Service
  backend:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: inventory-backend-prod
    ports:
      - "8080:80"
    environment:
      - DB_HOST=${DB_HOST}
      - DB_PORT=${DB_PORT}
      - DB_NAME=${DB_NAME}
      - DB_USER=${DB_USER}
      - DB_PASS=${DB_PASS}
      - COMPANY_NAME=${COMPANY_NAME}
      - COMPANY_ADDRESS=${COMPANY_ADDRESS}
      - COMPANY_CITY=${COMPANY_CITY}
      - COMPANY_POSTAL_CODE=${COMPANY_POSTAL_CODE}
      - COMPANY_COUNTRY=${COMPANY_COUNTRY}
      - COMPANY_PHONE=${COMPANY_PHONE}
      - COMPANY_EMAIL=${COMPANY_EMAIL}
      - COMPANY_Y_TUNNUS=${COMPANY_Y_TUNNUS}
      - UPLOAD_MAX_SIZE=${UPLOAD_MAX_SIZE:-10M}
      - ALLOWED_FILE_TYPES=${ALLOWED_FILE_TYPES:-pdf,doc,docx,xls,xlsx,jpg,jpeg,png,gif}
    volumes:
      - uploads_data:/var/www/html/uploads
    networks:
      - inventory-network
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost/api/company.php"]
      interval: 30s
      timeout: 10s
      retries: 3

  # Frontend Vue.js Service
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
      args:
        - VUE_APP_API_URL=${VUE_APP_API_URL:-http://localhost:8080}
    container_name: inventory-frontend-prod
    ports:
      - "3000:80"
    depends_on:
      - backend
    networks:
      - inventory-network
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost/"]
      interval: 30s
      timeout: 10s
      retries: 3

  # Redis Cache Service
  redis:
    image: redis:7-alpine
    container_name: inventory-redis-prod
    volumes:
      - redis_data:/data
      - ./docker/redis/redis.conf:/usr/local/etc/redis/redis.conf:ro
    networks:
      - inventory-network
    restart: unless-stopped
    command: redis-server /usr/local/etc/redis/redis.conf
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  redis_data:
    driver: local
  uploads_data:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ${UPLOADS_PATH:-/var/inventory/uploads}

networks:
  inventory-network:
    driver: bridge
