services:
  db:
    image: postgres:16
    restart: unless-stopped
    environment:
      POSTGRES_DB: mv_rent
      POSTGRES_USER: ${DB_USER:-postgres}
      POSTGRES_PASSWORD: ${DB_PASSWORD:?set DB_PASSWORD in .env}
    volumes:
      - db-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-postgres} -d mv_rent"]
      interval: 10s
      timeout: 5s
      retries: 6

  app:
    build: .
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    environment:
      DB_URL: jdbc:postgresql://db:5432/mv_rent
      DB_USER: ${DB_USER:-postgres}
      DB_PASSWORD: ${DB_PASSWORD}
      STORAGE_DIR: /data/uploads
      # Optional integrations — safe defaults; override in .env to activate
      MAIL_ENABLED: ${MAIL_ENABLED:-false}
      MAIL_HOST: ${MAIL_HOST:-}
      MAIL_PORT: ${MAIL_PORT:-587}
      MAIL_USERNAME: ${MAIL_USERNAME:-}
      MAIL_PASSWORD: ${MAIL_PASSWORD:-}
      MAIL_FROM: ${MAIL_FROM:-no-reply@mvrent.local}
      MAIL_ADMIN: ${MAIL_ADMIN:-admin@mvrent.local}
      TELEMATICS_API_KEY: ${TELEMATICS_API_KEY:-}
      GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID:-not-configured}
      GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET:-not-configured}
    volumes:
      - uploads:/data/uploads
    ports:
      # host:container — default 80 on the server; override HTTP_PORT locally
      - "${HTTP_PORT:-80}:8080"

volumes:
  db-data:
  uploads:
