version: '3.8'

services:
  tankstopp:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: tankstopp-app
    restart: unless-stopped
    ports:
      - "8080:8080"
    environment:
      # Application Configuration
      - TANKSTOPP_APP_ENVIRONMENT=production
      - TANKSTOPP_APP_DEBUG=false
      - TANKSTOPP_APP_NAME=TankStopp

      # Server Configuration
      - TANKSTOPP_SERVER_HOST=0.0.0.0
      - TANKSTOPP_SERVER_PORT=8080
      - TANKSTOPP_SERVER_READ_TIMEOUT=30s
      - TANKSTOPP_SERVER_WRITE_TIMEOUT=30s

      # Database Configuration
      - TANKSTOPP_DATABASE_PATH=/app/data/fuel_stops.db
      - TANKSTOPP_DATABASE_CONNECTION_POOL_MAX_IDLE_CONNECTIONS=25
      - TANKSTOPP_DATABASE_CONNECTION_POOL_MAX_OPEN_CONNECTIONS=200
      - TANKSTOPP_DATABASE_LOGGING_LEVEL=error
      - TANKSTOPP_DATABASE_MIGRATION_AUTO_MIGRATE=true

      # Security Configuration
      - TANKSTOPP_SECURITY_SESSION_SECURE_COOKIES=false
      - TANKSTOPP_SECURITY_SESSION_TIMEOUT=24h

      # Logging Configuration
      - TANKSTOPP_LOGGING_LEVEL=info
      - TANKSTOPP_LOGGING_FORMAT=json
      - TANKSTOPP_LOGGING_OUTPUT=stdout

      # External Services
      - TANKSTOPP_EXTERNAL_SERVICES_OVERPASS_API_URL=https://overpass-api.de/api/interpreter
      - TANKSTOPP_EXTERNAL_SERVICES_OVERPASS_API_TIMEOUT=30s

      # Feature Flags
      - TANKSTOPP_FEATURES_FUEL_STATION_SEARCH=true
      - TANKSTOPP_FEATURES_VEHICLE_MANAGEMENT=true
      - TANKSTOPP_FEATURES_STATISTICS_DASHBOARD=true
      - TANKSTOPP_FEATURES_API_ENDPOINTS=true
    volumes:
      # Data persistence
      - tankstopp_data:/app/data

      # Configuration (optional override)
      - ./config.production.yaml:/app/config.yaml:ro

      # Logs (optional)
      - tankstopp_logs:/app/logs
    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    networks:
      - tankstopp-network
    depends_on: []
    labels:
      - "com.tankstopp.service=app"
      - "com.tankstopp.version=1.0.0"

# Development override service
  tankstopp-dev:
    extends: tankstopp
    container_name: tankstopp-dev
    build:
      context: .
      dockerfile: Dockerfile
      target: builder
    environment:
      # Override for development
      - TANKSTOPP_APP_ENVIRONMENT=development
      - TANKSTOPP_APP_DEBUG=true
      - TANKSTOPP_DATABASE_LOGGING_LEVEL=info
      - TANKSTOPP_LOGGING_LEVEL=debug
      - TANKSTOPP_LOGGING_FORMAT=text
      - TANKSTOPP_DATABASE_PATH=/app/data/fuel_stops_dev.db
    ports:
      - "8081:8080"
    volumes:
      # Development data
      - tankstopp_dev_data:/app/data
      # Development config
      - ./config.development.yaml:/app/config.yaml:ro
      # Live code reload (optional)
      - .:/app:ro
    profiles:
      - dev

networks:
  tankstopp-network:
    driver: bridge
    labels:
      - "com.tankstopp.network=main"

volumes:
  tankstopp_data:
    driver: local
    labels:
      - "com.tankstopp.volume=production-data"

  tankstopp_dev_data:
    driver: local
    labels:
      - "com.tankstopp.volume=development-data"

  tankstopp_logs:
    driver: local
    labels:
      - "com.tankstopp.volume=logs"
