# ============================================================
# Docker Compose para desarrollo local
# ============================================================
# USO: 
#   1. Copia .env.example a .env y configura las variables
#   2. docker-compose up -d
# ============================================================

services:
  mysql:
    image: mysql:8.0
    container_name: impagos-mysql
    environment:
      MYSQL_DATABASE: ${DB_NAME:-impagos_db}
      MYSQL_USER: ${DB_USER:-impagos_user}
      MYSQL_PASSWORD: ${DB_PASS:?Error: DB_PASS no definido en .env}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:?Error: MYSQL_ROOT_PASSWORD no definido en .env}
    ports:
      - "3306:3306"
    command: 
      - --default-authentication-plugin=mysql_native_password
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
    volumes:
      - impagos_mysql_data:/var/lib/mysql
      - ./schema.sql:/docker-entrypoint-initdb.d/01-schema.sql:ro
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      timeout: 10s
      retries: 5
    restart: unless-stopped

  # Backend Node.js (opcional, para desarrollo)
  # backend:
  #   build: .
  #   container_name: impagos-backend
  #   depends_on:
  #     mysql:
  #       condition: service_healthy
  #   environment:
  #     DB_HOST: mysql
  #     DB_PORT: 3306
  #     DB_USER: ${DB_USER:-impagos_user}
  #     DB_PASS: ${DB_PASS}
  #     DB_NAME: ${DB_NAME:-impagos_db}
  #     ADMIN_SECRET: ${ADMIN_SECRET}
  #   ports:
  #     - "3000:3000"
  #   volumes:
  #     - ./facturas:/app/facturas
  #   restart: unless-stopped

volumes:
  impagos_mysql_data:
    name: impagos_mysql_data
