version: "3.9"

services:
  db:
    image: postgres:15
    container_name: fv_db
    env_file: ./.env
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      - db_data:/var/lib/postgresql/data
      - ../db/seeds/:/docker-entrypoint-initdb.d/:ro # ejecuta schema_SIM_PV.sql al iniciar
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 5s
      timeout: 5s
      retries: 10

  pgadmin:
    image: dpage/pgadmin4:8
    container_name: fv_pgadmin
    env_file: ./.env
    ports:
      - "5050:80"
    depends_on:
      - db

  backend:
    build:
      context: ../backend
      dockerfile: Dockerfile
    container_name: fv_api
    env_file: ./.env
    command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
    volumes:
      - ../backend:/app
    ports:
      - "8000:8000"
    depends_on:
      db:
        condition: service_healthy

  frontend:
    build:
      context: ../frontend
      dockerfile: Dockerfile
    container_name: fv_frontend
    ports:
      - "4200:80"
    depends_on:
      - backend

  nginx:
    image: nginx:alpine
    container_name: fv_nginx
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    ports:
      - "80:80"
    depends_on:
      - frontend
      - backend

volumes:
  db_data:
