import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'app/theme/app_theme.dart';
import 'app/router.dart';
import 'app/i18n/app_localizations.dart';
import 'core/updater/update_service.dart';
import 'core/updater/models/update_config.dart';
import 'core/push/push_service.dart';
import 'core/providers/notification_badge_manager.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // 初始化升级服务
  UpdateService().initialize(UpdateConfig.selfHosted(
    apiBaseUrl: 'https://api.gogenex.cn',
    enabled: true,
  ));

  // 初始化推送服务（无 Firebase 配置时静默失败）
  await PushService().initialize();

  // 初始化通知徽章管理器
  NotificationBadgeManager().initialize();

  runApp(const GenexIssuerApp());
}

/// Genex 发行方管理控制台 (Issuer Console)
///
/// 企业/政府/机构使用的券发行与管理工具
/// Web2体验：发券 = 创建优惠活动，链上铸造在后台自动完成
class GenexIssuerApp extends StatelessWidget {
  const GenexIssuerApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Genex Issuer Console',
      theme: AppTheme.light,
      debugShowCheckedModeBanner: false,
      locale: const Locale('zh', 'CN'),
      supportedLocales: const [
        Locale('zh', 'CN'),
        Locale('en', 'US'),
        Locale('ja', 'JP'),
      ],
      localizationsDelegates: const [
        AppLocalizationsDelegate(),
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      initialRoute: AppRouter.splash,
      onGenerateRoute: AppRouter.generateRoute,
    );
  }
}
