services:
  # Django
  django_auth:
    container_name: forperu_auth
    build: .
    volumes:
      - .:/app
    environment:
      MYSQL_NAME: forperu_db
      MYSQL_USER: root
      MYSQL_PASSWORD: admin
      MYSQL_HOST: db_auth
      MYSQL_PORT: 3306
      DEBUG: "True"
      SECRET_KEY: django-insecure-)++e$_cd1t%y8zcmjc@*jg2ux=3h8ul9n1omt-t7jpz=#tb0qx
      ALLOWED_HOSTS_DEV: "*"
      CORS_ORIGIN_WHITELIST_DEV: http://localhost:8000,http://localhost:8080,http://localhost:8081
      CSRF_TRUSTED_ORIGINS_DEV: http://localhost:8000,http://localhost:8080,http://localhost:8081
      META_WHATSAPP_TOKEN: EAA4jtghiVzwBPr8aLRXr2T9jvBTGDfagnuLJ6cAfT62RPyThu4oN8Ldip6FjPTrJEunm2VKYfu50ZAZB29vo2YjOZCBArNnvlrhwOLMUgh03TX0kU2bz4qJmWWdhILSyweIEW1qZAz6qvPAzqQqqSf2mPrIjZB1pQnuLbfvEQ0Q60KWZCVB3tkL63SyIbDZCQZDZD
      META_PHONE_NUMBER_ID: 782489831620404
      META_APP_ID: 1106305374945928

    #   - redis_auth

  # Mysql
  #db_auth:
  #  image: mysql:8.3
  #  container_name: forperu_db
  #  restart: always
  #  environment:
  #    MYSQL_ROOT_PASSWORD: admin
  #    MYSQL_DATABASE: forperu_db
  #  ports:
  #    - 3307:3306
  #  volumes:
  #    - .dbdata:/var/lib/mysql
    depends_on:
      db_auth:
        condition: service_healthy

  # ASP.NET Mobile API
  mobile_api:
    container_name: forperu_mobile
    build:
      context: ./mobile
      dockerfile: Dockerfile
    environment:
      ASPNETCORE_ENVIRONMENT: Development
      ASPNETCORE_FORWARDEDHEADERS_ENABLED: "true"
      ConnectionStrings__db: "server=db_auth;port=3306;database=forperu_db;user=root;password=admin"
    # No public port; Nginx will proxy to internal port 5000
    depends_on:
      db_auth:
        condition: service_healthy
    profiles:
      - app

  # Nginx reverse proxy
  nginx:
    image: nginx:alpine
    container_name: forperu_nginx
    depends_on:
      - django_auth
      - mobile_api
    ports:
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro

  # ASP.NET Mobile API (watch mode)
  mobile_api_watch:
    image: mcr.microsoft.com/dotnet/sdk:8.0
    container_name: forperu_mobile_watch
    working_dir: /src
    command: ["dotnet", "watch", "run", "--no-restore", "--urls", "http://0.0.0.0:5000"]
    environment:
      ASPNETCORE_ENVIRONMENT: Development
      ASPNETCORE_FORWARDEDHEADERS_ENABLED: "true"
      ConnectionStrings__db: "server=db_auth;port=3306;database=forperu_db;user=root;password=admin"
    volumes:
      - ./mobile:/src
      - nuget-packages:/root/.nuget/packages
    depends_on:
      db_auth:
        condition: service_healthy
    networks:
      default:
        aliases:
          - mobile_api
    profiles:
      - watch

  # Mysql
  db_auth:
    image: mysql:8.3
    container_name: forperu_mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: admin
      MYSQL_DATABASE: forperu_db
    ports:
      - "3307:3306"
    volumes:
      - ./.dbdata:/var/lib/mysql
      - ./migrations:/docker-entrypoint-initdb.d:ro
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-padmin"]
      interval: 5s
      timeout: 5s
      retries: 20

volumes:
  nuget-packages:
  
  # # Kafka
  # # Redis
  # redis_auth:
  #   image: redis:latest
  #   container_name: django_auth_api_redis
  #   ports:
  #     - 6379:6379