services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: assinaturas-app
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - "8000:8000"
    volumes:
      - .:/var/www/html
    command: >
      sh -lc "if [ ! -d vendor ]; then composer install; fi
      && php artisan serve --host=0.0.0.0 --port=8000"

  vite:
    image: node:22-bookworm-slim
    container_name: assinaturas-vite
    working_dir: /var/www/html
    environment:
      VITE_PORT: 5174
    ports:
      - "5174:5174"
    volumes:
      - .:/var/www/html
    command: >
      sh -lc "if [ ! -d node_modules ]; then npm install; fi
      && npm run dev -- --host 0.0.0.0 --port 5174"

  postgres:
    image: postgres:16
    container_name: assinaturas-postgres
    environment:
      POSTGRES_DB: assinaturas
      POSTGRES_USER: assinaturas_user
      POSTGRES_PASSWORD: assinaturas_dev_password
    ports:
      - "5433:5432"
    volumes:
      - assinaturas_pg16_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U assinaturas_user -d assinaturas"]
      interval: 5s
      timeout: 5s
      retries: 10

volumes:
  assinaturas_pg16_data:
