version: '3.8'

services:
  # Complete Inventory Solution (Single Container)
  inventory-app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: inventory-app
    ports:
      - "${FRONTEND_PORT:-80}:80"
    environment:
      - DB_HOST=${DB_HOST}
      - DB_PORT=${DB_PORT:-3306}
      - DB_NAME=${DB_NAME}
      - DB_USER=${DB_USER}
      - DB_PASS=${DB_PASS}
      - COMPANY_NAME=${COMPANY_NAME:-Inventory Management}
      - COMPANY_ADDRESS=${COMPANY_ADDRESS:-123 Business St}
      - COMPANY_CITY=${COMPANY_CITY:-Helsinki}
      - COMPANY_POSTAL_CODE=${COMPANY_POSTAL_CODE:-00100}
      - COMPANY_COUNTRY=${COMPANY_COUNTRY:-Finland}
      - COMPANY_PHONE=${COMPANY_PHONE:-+358 123 456 789}
      - COMPANY_EMAIL=${COMPANY_EMAIL:-info@company.com}
      - COMPANY_Y_TUNNUS=${COMPANY_Y_TUNNUS:-1234567-8}
      - UPLOAD_MAX_SIZE=${UPLOAD_MAX_SIZE:-10M}
      - ALLOWED_FILE_TYPES=${ALLOWED_FILE_TYPES:-pdf,doc,docx,xls,xlsx,jpg,jpeg,png,gif}
    volumes:
      - ./uploads:/var/www/html/uploads
      - ./attachments:/var/www/html/attachments
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost/api/company.php"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  # Redis Cache Service (Optional)
  redis:
    image: redis:7-alpine
    container_name: inventory-redis
    ports:
      - "${REDIS_PORT:-6379}:6379"
    volumes:
      - redis_data:/data
    restart: unless-stopped
    command: redis-server --appendonly yes

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