services:
  db:
    image: postgres:16
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-camo}
      POSTGRES_USER: ${POSTGRES_USER:-camo}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-camo_dev_password_change_me}
    volumes:
      - camo_pgdata:/var/lib/postgresql/data
    networks:
      - camo_net
    restart: unless-stopped

  api:
    build: ./api
    environment:
      DATABASE_URL: ${DATABASE_URL:-postgresql+psycopg://camo:camo_dev_password_change_me@db:5432/camo}
      SEED_PT_EMAIL: ${SEED_PT_EMAIL:-mpizarro@camo.local}
      JWT_SECRET: ${JWT_SECRET:-change_me_long_random_string}
      JWT_EXPIRE_MIN: ${JWT_EXPIRE_MIN:-60}
      AUTH_LOGIN_EMAIL: ${AUTH_LOGIN_EMAIL:-dgarciab@camo.local}
      AUTH_LOGIN_PASSWORD: ${AUTH_LOGIN_PASSWORD:-admin123}
      APP_BASE_URL: ${APP_BASE_URL:-https://camofit.cl}
      SMTP_HOST: ${SMTP_HOST:-}
      SMTP_PORT: ${SMTP_PORT:-587}
      SMTP_USERNAME: ${SMTP_USERNAME:-}
      SMTP_PASSWORD: ${SMTP_PASSWORD:-}
      SMTP_FROM_EMAIL: ${SMTP_FROM_EMAIL:-}
      SMTP_FROM_NAME: ${SMTP_FROM_NAME:-CamoFit}
      SMTP_USE_TLS: ${SMTP_USE_TLS:-true}
      SMTP_USE_SSL: ${SMTP_USE_SSL:-false}
      PASSWORD_RESET_TOKEN_EXPIRE_MIN: ${PASSWORD_RESET_TOKEN_EXPIRE_MIN:-15}
    depends_on:
      - db
    networks:
      - camo_net
    restart: unless-stopped

  web:
    build:
      context: ./web
      args:
        NEXT_PUBLIC_API_BASE: ${NEXT_PUBLIC_API_BASE:-/api}
        NEXT_PUBLIC_REQUIRE_TRAINER_PROFILE_COMPLETE: ${NEXT_PUBLIC_REQUIRE_TRAINER_PROFILE_COMPLETE:-true}
        NEXT_PUBLIC_ENABLE_CLIENT_WELLNESS_CHECKS: ${NEXT_PUBLIC_ENABLE_CLIENT_WELLNESS_CHECKS:-false}
        NEXT_PUBLIC_ENV: ${NEXT_PUBLIC_ENV:-production}
    environment:
      NEXT_PUBLIC_API_BASE: ${NEXT_PUBLIC_API_BASE:-/api}
      NEXT_PUBLIC_REQUIRE_TRAINER_PROFILE_COMPLETE: ${NEXT_PUBLIC_REQUIRE_TRAINER_PROFILE_COMPLETE:-true}
      NEXT_PUBLIC_ENABLE_CLIENT_WELLNESS_CHECKS: ${NEXT_PUBLIC_ENABLE_CLIENT_WELLNESS_CHECKS:-false}
      NEXT_PUBLIC_ENV: ${NEXT_PUBLIC_ENV:-production}
    depends_on:
      - api
    networks:
      - camo_net
    restart: unless-stopped

  nginx:
    image: nginx:alpine
    ports:
      - "8082:80"  # Puerto interno, no conflictúa con Apache en 80
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - web
      - api
    networks:
      - camo_net
    restart: unless-stopped

networks:
  camo_net:

volumes:
  camo_pgdata:
