import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'app/app.dart';
import 'features/notifications/notification_service.dart';
import 'firebase_options.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  try {
    await dotenv.load(fileName: 'assets/.env');
  } catch (_) {
    // .env no disponible — api_client.dart usa los valores por defecto
  }
  try {
    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );
  } on UnsupportedError {
    await Firebase.initializeApp();
  }
  // Registra handlers FCM (foreground + background), pide permisos
  // POST_NOTIFICATIONS y crea el canal Android `recolecta_alerts`.
  await NotificationService.initialize();
  runApp(const ProviderScope(child: RecolectaApp()));
}
