version: '3.8'

services:
  # Unified Backend + Frontend Application (Production)
  app:
    build:
      context: .
      dockerfile: Dockerfile.unified
      args:
        - VUE_APP_API_URL=/api
    container_name: inventory-app-prod
    ports:
      - "${FRONTEND_PORT:-3000}:80"
    environment:
      # Database Configuration
      - DB_HOST=${DB_HOST:-127.0.0.1}
      - DB_PORT=${DB_PORT:-3306}
      - DB_NAME=${DB_NAME:-inventory_db}
      - DB_USER=${DB_USER:-root}
      - DB_PASS=${DB_PASS:-root}
      
      # Company Information
      - COMPANY_NAME=${COMPANY_NAME:-Your Company Name}
      - COMPANY_ADDRESS=${COMPANY_ADDRESS:-123 Business Street}
      - COMPANY_POSTAL_CODE=${COMPANY_POSTAL_CODE:-00100}
      - COMPANY_CITY=${COMPANY_CITY:-Helsinki}
      - 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}
      
      # File Upload Configuration
      - UPLOAD_MAX_SIZE=${UPLOAD_MAX_SIZE:-10M}
      - ALLOWED_FILE_TYPES=${ALLOWED_FILE_TYPES:-pdf,doc,docx,xls,xlsx,jpg,jpeg,png,gif}
      - UPLOADS_PATH=${UPLOADS_PATH:-./uploads}
      
      # Frontend Configuration (relative path for internal communication)
      - VUE_APP_API_URL=/api
      
      # Optional: Redis Configuration
      - REDIS_HOST=${REDIS_HOST:-redis}
      - REDIS_PORT=${REDIS_PORT:-6379}
      
      # Optional: Email Configuration (for future use)
      - MAIL_HOST=${MAIL_HOST:-smtp.gmail.com}
      - MAIL_PORT=${MAIL_PORT:-587}
      - MAIL_USERNAME=${MAIL_USERNAME:-your-email@gmail.com}
      - MAIL_PASSWORD=${MAIL_PASSWORD:-your-app-password}
    
    volumes:
      - ./uploads:/var/www/html/uploads
      - ./backend:/var/www/html
    networks:
      - inventory-network
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost/api/company.php"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  # Redis Service (optional)
  redis:
    image: redis:7-alpine
    container_name: inventory-redis-prod
    ports:
      - "${REDIS_PORT:-6379}:6379"
    volumes:
      - redis_data:/data
    networks:
      - inventory-network
    restart: unless-stopped
    command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru

# Networks
networks:
  inventory-network:
    driver: bridge

# Volumes
volumes:
  uploads_data:
    driver: local
  redis_data:
    driver: local
