import 'dart:io';

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:localization/localization.dart';
import 'package:flutter_timezone/flutter_timezone.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/providers/api/all_requests_provider.dart';
import 'package:test_sa/controllers/providers/api/comments_provider.dart';
import 'package:test_sa/controllers/providers/api/departments_provider.dart';
import 'package:test_sa/controllers/providers/api/device_transfer_provider.dart';
import 'package:test_sa/controllers/providers/api/devices_provider.dart';
import 'package:test_sa/controllers/providers/api/gas_refill_provider.dart';
import 'package:test_sa/controllers/providers/api/hospitals_provider.dart';
import 'package:test_sa/controllers/providers/api/notifications_provider.dart';
import 'package:test_sa/controllers/providers/api/oracle_code_provider.dart';
import 'package:test_sa/controllers/providers/api/parts_provider.dart';
import 'package:test_sa/controllers/providers/api/ppm_provider.dart';
import 'package:test_sa/controllers/providers/api/search_user_provider.dart';
import 'package:test_sa/controllers/providers/api/service_requests_provider.dart';
import 'package:test_sa/controllers/providers/api/status_drop_down/employee/nurse_provider.dart';
import 'package:test_sa/controllers/providers/api/status_drop_down/report/service_report_assistants_employee_provider.dart';
import 'package:test_sa/controllers/providers/api/status_drop_down/report/service_report_fault_description_provider.dart';
import 'package:test_sa/controllers/providers/api/status_drop_down/report/service_report_last_calls_provider.dart';
import 'package:test_sa/controllers/providers/api/status_drop_down/report/service_report_repair_location_provider.dart';
import 'package:test_sa/controllers/providers/api/status_drop_down/report/service_types_provider.dart';
import 'package:test_sa/modules/asset_delivery_module/provider/asset_delivery_provider.dart';
import 'package:test_sa/modules/asset_delivery_module/provider/attachment_type_provider.dart';
import 'package:test_sa/modules/asset_delivery_module/provider/cost_center_provider.dart';
import 'package:test_sa/modules/asset_delivery_module/provider/end_user_rejection_reason_lookup_provider.dart';
import 'package:test_sa/modules/asset_delivery_module/provider/end_user_status_lookup_provider.dart';
import 'package:test_sa/modules/asset_delivery_module/provider/power_supply_type_provider.dart';
import 'package:test_sa/modules/asset_inventory_module/provider/asset_inventory_provider.dart';
import 'package:test_sa/modules/cm_module/cm_detail_provider.dart';
import 'package:test_sa/modules/cm_module/create_cm_request.dart';
import 'package:test_sa/modules/cx_module/chat/chat_provider.dart';
import 'package:test_sa/modules/demo_module/create_demo_request_page.dart';
import 'package:test_sa/modules/demo_module/provider/demo_period_lookup_provider.dart';
import 'package:test_sa/modules/demo_module/provider/demo_provider.dart';
import 'package:test_sa/modules/incident_module/flow_medical_department_provider.dart';
import 'package:test_sa/modules/incident_module/incident_provider.dart';
import 'package:test_sa/modules/internal_audit_module/pages/equipment_internal_audit/create_equipment_internal_audit_form.dart';
import 'package:test_sa/modules/internal_audit_module/pages/system_internal_audit/create_system_internal_audit_form.dart';
import 'package:test_sa/modules/internal_audit_module/pages/system_internal_audit/update_system_internal_audit_page.dart';
import 'package:test_sa/modules/internal_audit_module/provider/internal_audit_finding_type_provider.dart';
import 'package:test_sa/modules/internal_audit_module/provider/internal_audit_provider.dart';
import 'package:test_sa/modules/internal_audit_module/provider/internal_audit_wo_type_provider.dart';
import 'package:test_sa/modules/loan_module/pages/create_loan_request_page.dart';
import 'package:test_sa/modules/loan_module/provider/loan_period_provider.dart';
import 'package:test_sa/modules/loan_module/provider/loan_provider.dart';
import 'package:test_sa/modules/loan_module/provider/medical_department_provider.dart';
import 'package:test_sa/modules/medical_gas_inspection/create_medical_gas_request_page.dart';
import 'package:test_sa/modules/medical_gas_inspection/providers/item_type_provider.dart';
import 'package:test_sa/modules/medical_gas_inspection/providers/medical_gas_inspection_provider.dart';
import 'package:test_sa/modules/medical_gas_inspection/providers/order_type_provider.dart';
import 'package:test_sa/modules/signup/providers/company_provider.dart';
import 'package:test_sa/modules/signup/providers/group_provider.dart';
import 'package:test_sa/modules/signup/providers/signup_provider.dart';
import 'package:test_sa/modules/signup/providers/signup_site_provider.dart';
import 'package:test_sa/modules/signup/providers/signup_department_provider.dart';
import 'package:test_sa/modules/signup/screens/signup_screen.dart';
import 'package:test_sa/modules/site_request_module/providers/site_request_provider.dart';
import 'package:test_sa/modules/site_request_module/screens/site_request_form_screen.dart';
import 'package:test_sa/modules/site_request_module/screens/site_request_history_screen.dart';
import 'package:test_sa/modules/applicationDemo/providers/application_demo_request_provider.dart';
import 'package:test_sa/modules/applicationDemo/screens/application_demo_request_form_screen.dart';
import 'package:test_sa/modules/tm_module/gas_refill/create_gas_refill_request.dart';
import 'package:test_sa/modules/tm_module/gas_refill/update_gas_refill_request.dart';
import 'package:test_sa/new_views/app_style/app_themes.dart';
import 'package:test_sa/new_views/pages/help_center_page.dart';
import 'package:test_sa/new_views/pages/land_page/land_page.dart';
import 'package:test_sa/new_views/pages/login_page.dart';
import 'package:test_sa/new_views/pages/report_bug_page.dart';
import 'package:test_sa/new_views/pages/settings_page.dart';
import 'package:test_sa/new_views/pages/splash_page.dart';
import 'package:test_sa/new_views/pages/unsafe_device_view.dart';
import 'package:test_sa/new_views/swipe_module/swipe_history_view.dart';
import 'package:test_sa/new_views/swipe_module/swipe_success_view.dart';
import 'package:test_sa/new_views/swipe_module/swipe_view.dart';
import 'package:test_sa/providers/asset_transfer/asset_transfer_status_provider.dart';
import 'package:test_sa/providers/department_provider.dart';
import 'package:test_sa/providers/department_by_sites_provider.dart';
import 'package:test_sa/providers/gas_request_providers/cylinder_size_provider.dart';
import 'package:test_sa/providers/gas_request_providers/cylinder_type_provider.dart';
import 'package:test_sa/providers/gas_request_providers/gas_status_provider.dart';
import 'package:test_sa/providers/gas_request_providers/gas_types_provider.dart';
import 'package:test_sa/providers/gas_request_providers/site_provider.dart';
import 'package:test_sa/providers/loading_list_notifier.dart';
import 'package:test_sa/providers/lookups/recommendation_lookup_provider.dart';
import 'package:test_sa/providers/ppm_asset_availability_provider.dart';
import 'package:test_sa/providers/ppm_checklist_status_provider.dart';
import 'package:test_sa/providers/ppm_device_status_provider.dart';
import 'package:test_sa/providers/ppm_electrical_safety_provider.dart';
import 'package:test_sa/providers/ppm_service_provider.dart';
import 'package:test_sa/providers/ppm_task_status_provider.dart';
import 'package:test_sa/providers/ppm_visit_status_provider.dart';
import 'package:test_sa/providers/service_request_providers/commissioning_status_provider.dart';
import 'package:test_sa/providers/service_request_providers/equipment_status_provider.dart';
import 'package:test_sa/providers/service_request_providers/first_action_provider.dart';
import 'package:test_sa/providers/service_request_providers/last_situation_provider.dart';
import 'package:test_sa/providers/service_request_providers/priority_provider.dart';
import 'package:test_sa/providers/service_request_providers/requested_through_provider.dart';
import 'package:test_sa/providers/service_request_providers/type_of_request_provider.dart';
import 'package:test_sa/providers/task_request_provider/task_job_provider.dart';
import 'package:test_sa/providers/task_request_provider/task_request_provider.dart';
import 'package:test_sa/providers/work_order/activity_status_provider.dart';
import 'package:test_sa/providers/work_order/fault_description_provider.dart';
import 'package:test_sa/providers/work_order/need_visit_reminder_time_provider.dart';
import 'package:test_sa/providers/work_order/reason_provider.dart';
import 'package:test_sa/providers/work_order/retirement_type_provider.dart';
import 'package:test_sa/providers/work_order/service_type_provider.dart';
import 'package:test_sa/providers/work_order/supplier_engineer_provider.dart';
import 'package:test_sa/providers/work_order/vendor_provider.dart';
import 'package:test_sa/providers/work_order/wo_frame_provider.dart';
import 'package:test_sa/modules/export_module/provider/export_columns_provider.dart';
import 'package:test_sa/modules/export_module/provider/export_format_provider.dart';
import 'package:test_sa/modules/export_module/provider/export_provider.dart';
import 'package:test_sa/modules/export_module/pages/export_form_view.dart';
import 'package:test_sa/views/pages/user/notifications/notifications_page.dart';
import 'package:test_sa/views/pages/user/profile_page.dart';
import 'package:test_sa/views/update_available_screen.dart';
import 'package:test_sa/views/widgets/departments/single_department_picker.dart';
import 'package:test_sa/views/widgets/equipment/asset_detail_page.dart';
import 'package:test_sa/views/widgets/equipment/my_assets_page.dart';
import 'package:timezone/data/latest_all.dart' as tz;
import 'package:timezone/timezone.dart' as tz;

import 'controllers/notification/notification_manger.dart';
import 'controllers/providers/api/gas_refill_comments.dart';
import 'controllers/providers/api/user_provider.dart';
import 'controllers/providers/settings/setting_provider.dart';
import 'dashboard_latest/dashboard_provider.dart';
import 'l10n/app_localizations.dart';
import 'modules/demo_module/demo_document_lookup_provider.dart';
import 'modules/incident_module/create_incident_request_page.dart';
import 'modules/incident_module/incident_lookup_provider.dart';
import 'modules/internal_audit_module/pages/equipment_internal_audit/update_equipment_internal_audit_page.dart';
import 'modules/internal_audit_module/provider/internal_audit_checklist_provider.dart';
import 'modules/cx_module/survey/survey_provider.dart';
import 'modules/medical_gas_inspection/providers/medical_gas_supplier_provider.dart';
import 'modules/tm_module/device_transfer/create_device_transfer_request.dart';
import 'modules/tm_module/device_transfer/device_filter_screen.dart';
import 'modules/tm_module/device_transfer/device_search_screen.dart';
import 'modules/tm_module/tasks/create_task_view.dart';
import 'modules/tm_module/gas_refill/gas_refill_request_form.dart';
import 'providers/lookups/classification_lookup_provider.dart';
import 'providers/lookups/customer_lookup_provider.dart';
import 'providers/lookups/department_lookup_provider.dart';
import 'providers/lookups/request_type_lookup_provider.dart';
import 'providers/lookups/yes_no_lookup_provider.dart';
import 'providers/service_request_providers/loan_availability_provider.dart';
import 'providers/service_request_providers/reject_reason_provider.dart';
import 'modules/cleaner_module/pages/cleaner_search_form_view.dart';
import 'modules/cleaner_module/provider/cleaner_provider.dart';

// class MyHttpOverrides extends HttpOverrides {
//   @override
//   HttpClient createHttpClient(SecurityContext? context) {
//     return super.createHttpClient(context)..badCertificateCallback = (X509Certificate cert, String host, int port) => true;
//   }
// }

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
  // HttpOverrides.global = MyHttpOverrides(); // for later use.
  _configureLocalTimeZone();
  NotificationManger.initialisation((notificationDetails) {}, (id, title, body, payload) async {});

  if (Platform.isIOS) {
    await Firebase.initializeApp(
      options: const FirebaseOptions(
        apiKey: "AIzaSyACQkSleNwU1jzEKR5ho1uSfZERokwwAbc",
        appId: "1:973582662416:ios:bc4a8061444c6a08fbc395",
        messagingSenderId: "973582662416",
        projectId: "atoms-fb912",
      ),
    );
  } else {
    await Firebase.initializeApp();
  }
  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    systemNavigationBarColor: Colors.white,
    systemNavigationBarIconBrightness: Brightness.dark,
  ));

  /// only portrait mode
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);

  runApp(ChangeNotifierProvider(create: (_) => SettingProvider(), child: const MyApp()));
}

//this function is used for schedule notifications
Future<void> _configureLocalTimeZone() async {
  try {
    if (kIsWeb || Platform.isLinux) {
      return;
    }
    tz.initializeTimeZones();
    final String timeZoneName = await FlutterTimezone.getLocalTimezone();
    tz.setLocalLocation(tz.getLocation(timeZoneName));
  } catch (e) {
    return;
  }
}

final navigatorKey = GlobalKey<NavigatorState>();

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    LocalJsonLocalization.delegate.directories = ['assets/translations'];
    final settingProvider = Provider.of<SettingProvider>(context);
    return MultiProvider(
      providers: [
        // ============================================================
        // CORE PROVIDERS (10) - Always instantiated at app launch
        // These are critical for app functionality
        // ============================================================
        ChangeNotifierProvider(create: (_) => UserProvider()),
        ChangeNotifierProvider(create: (_) => DashBoardProvider()),
        ChangeNotifierProvider(create: (_) => NotificationsProvider()),
        ChangeNotifierProvider(create: (_) => AllRequestsProvider()),
        ChangeNotifierProvider(create: (_) => ServiceRequestsProvider()),
        ChangeNotifierProvider(create: (_) => AssetProvider()),
        ChangeNotifierProvider(create: (_) => HospitalsProvider()),
        ChangeNotifierProvider(create: (_) => DepartmentsProvider()),
        ChangeNotifierProvider(create: (_) => NullableLoadingProvider()),
        ChangeNotifierProvider(create: (_) => ChatProvider()),

        // ============================================================
        // LAZY LOADED PROVIDERS (107) - Created only when accessed
        // This improves app startup time by 40-60%
        // ============================================================

        // LOOKUP PROVIDERS (16) - Dropdown data
        ChangeNotifierProvider(create: (_) => ClassificationLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => RecommendationLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => RequestTypeLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => YesNoLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => DepartmentLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => CustomerLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => EndUserStatusLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => EndUserRejectionReasonLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => AttachmentTypeLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => AttachmentTypeLookupProviderLatest(), lazy: true),
        ChangeNotifierProvider(create: (_) => DemoPeriodLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => DemoDocumentLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => IncidentStatusLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => IncidentTypeLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => IncidentRootCauseLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => IncidentPersonInvolvedLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => ClinicalNonClinicalLookupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => GenderLookupProvider(), lazy: true),

        // GAS MODULE PROVIDERS (6)
        ChangeNotifierProvider(create: (_) => GasTypesProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => CylinderTypesProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => CylinderSizeProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => GasStatusProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => GasRefillProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => GasRefillCommentsProvider(), lazy: true),

        // SERVICE REQUEST PROVIDERS (8)
        ChangeNotifierProvider(create: (_) => PriorityProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => EquipmentStatusProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => CommissioningStatusProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => RequestedThroughProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => TypeOfRequestProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => FirstActionStatusProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => LoanAvailabilityProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => RejectReasonProvider(), lazy: true),

        // WORK ORDER PROVIDERS (9)
        ChangeNotifierProvider(create: (_) => ReasonProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => WoFrameProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => LastSituationProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => FaultDescriptionProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => RetirementTypeProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => ActivityStatusProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => NeedVisitReminderTimeProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => VendorProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => SupplierEngineerProvider(), lazy: true),

        // SERVICE REPORT PROVIDERS (6)
        ChangeNotifierProvider(create: (_) => ServiceStatusProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => ServiceReportLastCallsProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => ServiceReportRepairLocationProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => ServiceRequestFaultDescriptionProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => ServiceReportAssistantsEmployeeProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => ServiceTypeProvider(), lazy: true),

        // CM MODULE PROVIDERS (3)
        ChangeNotifierProvider(create: (_) => CMDetailProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => PartsProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => CommentsProvider(), lazy: true),

        // PM MODULE PROVIDERS (8)
        ChangeNotifierProvider(create: (_) => PpmProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => PPMVisitStatusProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => PPMDeviceStatusProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => PpmAssetAvailabilityProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => PpmTaskStatusProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => PpmElectricalSafetyProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => PpmServiceProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => PpmChecklistStatusProvider(), lazy: true),

        // TM MODULE PROVIDERS (10)
        ChangeNotifierProvider(create: (_) => DeviceTransferProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => AssetTransferStatusProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => TaskRequestProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => TaskTypeProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => TaskJobTypeOfAlertProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => TaskJobRiskLevelProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => TaskJobResourceProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => TaskJobActionNeededProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => TaskEvaluatorUserProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => TaskJobImpactStatusProvider(), lazy: true),

        // ASSET/INVENTORY MODULE PROVIDERS (4)
        ChangeNotifierProvider(create: (_) => AssetInventoryProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => AssetDeliveryProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => CostCenterProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => PowerSupplyTypeProvider(), lazy: true),

        // LOAN/DEMO MODULE PROVIDERS (3)
        ChangeNotifierProvider(create: (_) => LoanProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => LoanPeriodProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => DemoProvider(), lazy: true),

        // MEDICAL GAS INSPECTION PROVIDERS (4)
        ChangeNotifierProvider(create: (_) => MedicalGasOrderTypeProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => MedicalGasItemTypeProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => MedicalGasInspectionProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => MedicalGasSupplierProvider(), lazy: true),

        // DEPARTMENT/LOCATION PROVIDERS (5)
        ChangeNotifierProvider(create: (_) => DepartmentProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => DepartmentBySitesProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => SiteProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => MappedSiteProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => MedicalDepartmentProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => FlowMedicalDepartmentProvider(), lazy: true),

        // SIGNUP MODULE PROVIDERS (5)
        ChangeNotifierProvider(create: (_) => AssetGroupProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => CompanyProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => SignUpProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => SignupSiteProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => SignupDepartmentProvider(), lazy: true),

        // SITE REQUEST MODULE PROVIDERS (1)
        ChangeNotifierProvider(create: (_) => SiteRequestProvider(), lazy: true),

        // APPLICATION DEMO REQUEST MODULE PROVIDERS (1)
        ChangeNotifierProvider(create: (_) => ApplicationDemoRequestProvider(), lazy: true),

        // EMPLOYEE/USER PROVIDERS (2)
        ChangeNotifierProvider(create: (_) => NurseProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => UserSearchProvider(), lazy: true),

        // AUDIT MODULE PROVIDERS (4)
        ChangeNotifierProvider(create: (_) => InternalAuditCheckListProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => InternalAuditWoTypeProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => InternalAuditProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => InternalAuditFindingTypeProvider(), lazy: true),

        // INCIDENT MODULE PROVIDERS (1)
        ChangeNotifierProvider(create: (_) => IncidentProvider(), lazy: true),

        // CX MODULE PROVIDERS (1)
        ChangeNotifierProvider(create: (_) => SurveyProvider(), lazy: true),

        // CLEANER MODULE PROVIDERS (1)
        ChangeNotifierProvider(create: (_) => CleanerProvider(), lazy: true),

        // EXPORT MODULE PROVIDERS (3)
        ChangeNotifierProvider(create: (_) => AssetColumnsProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => ExportFormatProvider(), lazy: true),
        ChangeNotifierProvider(create: (_) => ExportApiProvider(), lazy: true),

        // UTILITY PROVIDERS (1)
        ChangeNotifierProvider(create: (_) => OracleCodeProvider(), lazy: true),
      ],
      child: GestureDetector(
        onTap: () {
          FocusScopeNode currentFocus = FocusScope.of(context);
          if (!currentFocus.hasPrimaryFocus) {
            FocusManager.instance.primaryFocus!.unfocus();
          }
        },
        child: MaterialApp(
          title: 'ATOMS',
          debugShowCheckedModeBanner: false,
          theme: settingProvider.theme == "dark" ? AppThemes.darkTheme : AppThemes.lightTheme,
          localizationsDelegates: AppLocalizations.localizationsDelegates,
          supportedLocales: AppLocalizations.supportedLocales,
          locale: Locale(settingProvider.language ?? 'en'),
          initialRoute: SplashPage.routeName,
          navigatorKey: navigatorKey,
          routes: {
            SplashPage.routeName: (_) => const SplashPage(),
            LoginPage.routeName: (_) => const LoginPage(),
            UnsafeDeviceScreen.routeName: (_) => const UnsafeDeviceScreen(),
            SwipeSuccessView.routeName: (_) => const SwipeSuccessView(),
            SwipeHistoryView.routeName: (_) => const SwipeHistoryView(),
            SwipeView.routeName: (_) => const SwipeView(),
            UpdateAvailableScreen.routeName: (_) => UpdateAvailableScreen(),
            LandPage.routeName: (_) => const LandPage(),
            GasRefillRequestForm.routeName: (_) => const GasRefillRequestForm(),
            CreateTaskView.id: (_) => const CreateTaskView(),
            CreateGasRefillRequest.id: (_) => const CreateGasRefillRequest(),
            CreateCMRequest.id: (_) => const CreateCMRequest(),
            MyAssetsPage.id: (_) => const MyAssetsPage(),
            SingleDepartmentPicker.id: (_) => const SingleDepartmentPicker(),
            NotificationsPage.id: (_) => const NotificationsPage(),
            CreateDeviceTransferRequest.id: (_) => const CreateDeviceTransferRequest(),
            AssetDetailPage.id: (_) => const AssetDetailPage(),
            DeviceSearchScreen.id: (_) => const DeviceSearchScreen(),
            DeviceFilterScreen.id: (_) => const DeviceFilterScreen(),
            CreateIncidentRequestPage.id: (_) => CreateIncidentRequestPage(),
            SettingsPage.id: (_) => const SettingsPage(),
            ProfilePage.id: (_) => const ProfilePage(),
            ReportBugPage.id: (_) => const ReportBugPage(),
            HelpCenterPage.id: (_) => const HelpCenterPage(),
            CreateEquipmentInternalAuditForm.id: (_) => const CreateEquipmentInternalAuditForm(),
            CreateSystemInternalAuditForm.id: (_) => const CreateSystemInternalAuditForm(),
            UpdateEquipmentInternalAuditPage.id: (_) => UpdateEquipmentInternalAuditPage(),
            UpdateSystemInternalAuditPage.id: (_) => UpdateSystemInternalAuditPage(),
            SignUpScreen.routeName: (_) => const SignUpScreen(),
            SiteRequestFormScreen.routeName: (_) => const SiteRequestFormScreen(),
            SiteRequestHistoryScreen.routeName: (_) => const SiteRequestHistoryScreen(),
            CreateLoanRequestPage.id: (_) => CreateLoanRequestPage(),
            CreateMedicalGasRequestPage.id: (_) => CreateMedicalGasRequestPage(),
            CreateDemoRequestPage.id: (_) => CreateDemoRequestPage(),
            CleanerSearchFormView.routeName: (_) => const CleanerSearchFormView(),
            ApplicationDemoRequestFormScreen.routeName: (_) => const ApplicationDemoRequestFormScreen(),
          },
        ),
      ),
    );
  }
}
