# Docker Compose pour développement local
# Usage: docker compose -f docker-compose.dev.yml up -d

services:
  # Base de données PostgreSQL
  postgres:
    image: postgres:17
    container_name: ptitspas-postgres-dev
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-admin}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-admin123}
      POSTGRES_DB: ${POSTGRES_DB:-ptitpas_db}
    ports:
      - "5433:5432"
    volumes:
      # Si le fichier d'init existe dans le dépôt database
      - ./migrations/01_init.sql:/docker-entrypoint-initdb.d/01_init.sql
      - postgres_dev_data:/var/lib/postgresql/data

    networks:
      - ptitspas_dev

  # Interface d'administration DB
  pgadmin:
    image: dpage/pgadmin4
    container_name: ptitspas-pgadmin-dev
    restart: unless-stopped
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-admin@ptits-pas.fr}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin123}
    ports:
      - "8080:80"
    depends_on:
      - postgres
    networks:
      - ptitspas_dev

  # Backend NestJS
  backend:
    build: 
      context: .
      dockerfile: Dockerfile
    container_name: ptitspas-backend-dev
    restart: unless-stopped
    environment:
      POSTGRES_HOST: ${POSTGRES_HOST:-postgres}
      POSTGRES_PORT: ${POSTGRES_PORT:-5432}
      POSTGRES_USER: ${POSTGRES_USER:-admin}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-admin123}
      POSTGRES_DB: ${POSTGRES_DB:-ptitpas_db}
      API_PORT: ${API_PORT:-3000}
      JWT_SECRET: ${JWT_SECRET:-dev-jwt-secret-key}
      JWT_EXPIRATION_TIME: ${JWT_EXPIRATION_TIME:-7d}
      NODE_ENV: ${NODE_ENV:-development}
    ports:
      - "3000:3000"
    depends_on:
      - postgres
    volumes:
      # Pour le hot reload en développement
      - ./src:/app/src
      - /app/node_modules
    networks:
      - ptitspas_dev

volumes:
  postgres_dev_data:

networks:
  ptitspas_dev:
    driver: bridge
