services:
  postgres:
    image: postgres:16-alpine
    container_name: midas-postgres
    environment:
      POSTGRES_USER: midas_dev
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-devpassword}
      POSTGRES_DB: midas_dev
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U midas_dev -d midas_dev"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - midas-network

  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: midas-pgadmin
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - "8080:80"
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@localhost.com
      PGADMIN_DEFAULT_PASSWORD: admin
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    networks:
      - midas-network

  app:
    build:
      context: .
      dockerfile: .docker/Dockerfile
    container_name: midas-app
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgresql://midas_dev:${POSTGRES_PASSWORD:-devpassword}@postgres:5432/midas_dev
    env_file:
      - .env.local
    volumes:
      - .:/app
      - /app/node_modules
      - /app/.next
    networks:
      - midas-network

volumes:
  postgres_data:
    driver: local
  pgadmin_data:
    driver: local

networks:
  midas-network:
    driver: bridge
