// ignore_for_file: non_constant_identifier_names

import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/architecture/middlewares/index.dart';
import 'package:flyinsono/architecture/router/index.dart';
import 'package:flyinsono/architecture/router/types.dart';
import 'package:flyinsono/architecture/values/features.dart';
import 'package:flyinsono/lab/pages/lab_login/index.dart';
import 'package:flyinsono/lab/pages/lab_main/index.dart';
import 'package:flyinsono/pages/college/bindings.dart';
import 'package:flyinsono/pages/college/view.dart';
import 'package:flyinsono/pages/college/widgets/exam_page.dart';
import 'package:flyinsono/pages/live_course/index.dart';
import 'package:flyinsono/pages/remedical/consultation_record_view/index.dart';
import 'package:flyinsono/pages/remote_controller/controller.dart';
import 'package:flyinsono/pages/remote_controller/view.dart';
import 'package:flyinsono/pages/third_party_page/Feedback/bindings.dart';
import 'package:flyinsono/pages/third_party_page/feedback/view.dart';
import 'package:flyinsono/pages/user/group_list/index.dart';
import 'package:flyinsono/views/common/device_live/device_live_list/controller.dart';
import 'package:flyinsono/views/desktop/device_live/device_live_detail/index.dart';
import 'package:flyinsono/views/desktop/device_live/device_live_list/index.dart';
import 'package:flyinsono/views/desktop/hardware_detection/bindings.dart';
import 'package:flyinsono/views/desktop/hardware_detection/widgets/detectionassistant_navigation.dart';
import 'package:flyinsono/views/desktop/laboratory/bindings.dart';
import 'package:flyinsono/views/desktop/laboratory/view.dart';
import 'package:flyinsono/views/desktop/laboratory/widgets/ai_laboratory.dart';
import 'package:flyinsono/views/desktop/laboratory/widgets/labratory.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/live_consultation/bindings.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/live_consultation/view.dart';
import 'package:flyinsono/pages/schedule/calendar/calendar_page/calendar_page.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/controller/real_time_consultation_controller.dart';
import 'package:flyinsono/pages/auth/auth_board/bindings.dart';
import 'package:flyinsono/pages/auth/auth_board/transition.dart';
import 'package:flyinsono/pages/auth/auth_board/view.dart';
import 'package:flyinsono/pages/auth/retrieve_password/bindings.dart';
import 'package:flyinsono/pages/auth/retrieve_password/view.dart';
import 'package:flyinsono/pages/auth/sign_in/bindings.dart';
import 'package:flyinsono/pages/auth/sign_in/view.dart';
import 'package:flyinsono/pages/auth/sign_up/bindings.dart';
import 'package:flyinsono/pages/auth/sign_up/view.dart';
import 'package:flyinsono/pages/index.dart';
import 'package:flyinsono/pages/measure/index.dart';
import 'package:flyinsono/pages/others/second_splash/bindings.dart';
import 'package:flyinsono/pages/others/second_splash/view.dart';
import 'package:flyinsono/pages/remedical/consultation/bindings.dart';
import 'package:flyinsono/pages/remedical/consultation/view.dart';
import 'package:flyinsono/pages/remedical/image_pool/bindings.dart';
import 'package:flyinsono/pages/remedical/image_pool/view.dart';
import 'package:flyinsono/pages/remedical/report/report_edit/bindings.dart';
import 'package:flyinsono/pages/remedical/report/report_edit/view.dart';
import 'package:flyinsono/pages/remedical/report_preview/bindings.dart';
import 'package:flyinsono/pages/remedical/report_preview/view.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/widgets/real_time_consultation_list.dart';
import 'package:flyinsono/views/desktop/user_setting/index.dart';
import 'package:flyinsono/pages/user/report_template/index.dart';
import 'package:flyinsono/pages/user/report_template/widgets/report_designer_page.dart';
import 'package:flyinsono/pages/user/user_center/widgets/change_password_page.dart';
import 'package:flyinsono/pages/user/user_device/bindings.dart';
import 'package:flyinsono/pages/user/user_device/index.dart';
import 'package:flyinsono/pages/user/user_device/widgets/add_or_edit_terminal.dart';
import 'package:get/get.dart';
import 'package:fis_jsonrpc/rpc.dart';
import '../../../views/mobile/past_video_player/index.dart';
import '../../../views/mobile/past_videos/index.dart';

const String PERSONCENTER = "PersonCenter";
const String MAINMENU = "MainMenu";

/// FIS的路由表构建器
class FRoutesDesktopBuilder {
  final List<FRouteSetting<dynamic>> _routes = [];

  /// 构建路由表
  List<FRouteSetting<dynamic>> build() {
    _buildCommonRoutes();
    _buildHomeRoutes();
    _buildAuthRoutes();
    _buildUserRoutes();
    _buildCollegeRouters();
    _buildOrgRoutes();
    _buildRemedicalRoutes();
    _buildRealTimeRemedicalRoutes();
    _buildLaboratoryRoutes();
    _buildThirdpartyPage();
    _buildLiveRoutes();
    _buildLabRouters();
    return _routes;
  }

  void _buildCommonRoutes() {
    _routes.add(
      FRouteSetting(
        RouteNames.App.Splash,
        () => SplashPage(),
        binding: SplashBinding(),
        transition: Transition.fade,
      ),
    );
    _routes.add(
      FRouteSetting(
        RouteNames.App.SecondSplash,
        () => SecondSplashPage(),
        binding: SecondSplashBinding(),
        transition: Transition.fade,
      ),
    );
    _routes.add(FErrorRouteSettings.NotFount);
    _routes.add(
      FRouteSetting(
        RouteNames.Error.Unauthorized,
        () => UnauthorizedPage(),
        transition: Transition.fade,
      ),
    );
  }

  void _buildCollegeRouters() {
    _routes.addAll([
      FRouteSetting(
        RouteNames.College.FlyinsonoCollege,
        () => FlyinsonoCollege(),
        binding: FlyinsonoCollegeBinding(),
      ),
      FRouteSetting(
        RouteNames.College.LiveCourseDetail,
        () => LiveCoursePage(),
        binding: LiveCourseBinding(),
      ),
      FRouteSetting(
        RouteNames.College.ExamPage,
        () => ExamPage(),
      ),
      FRouteSetting(
        RouteNames.College.PastVideos,
        () => PastVideosPage(),
        binding: PastVideosBinding(),
      ),
      FRouteSetting(
        RouteNames.College.PastVideoPlayer,
        () => PastVideoPlayerPage(),
        binding: PastVideoPlayerBinding(),
      )
    ]);
  }

  _buildLabRouters() {
    _routes.addAll([
      FRouteSetting(
        RouteNames.Lab.Login,
        () => QuickFWidget(LabLoginPage()),
        binding: LabLoginBinding(),
      ),
      FRouteSetting(
        RouteNames.Lab.Main,
        () => QuickFWidget(LabMainPage()),
        binding: LabMainBinding(),
      ),
    ]);
  }

  void _buildUserRoutes() {
    _routes.addAll([
      FRouteSetting(
        RouteNames.User.RoleApply,
        () => UserIdAuthApplyPage(),
        binding: UserIdAuthApplyBinding(),
      ),
      FRouteSetting(
        RouteNames.User.ChangePasswordPage,
        () => ChangePasswordPage(),
      ),
      FRouteSetting(
        RouteNames.User.RoleAuth,
        () => RoleAuthenticationPage(),
        binding: RoleAuthenticationBinding(),
      ),
      FRouteSetting(
        RouteNames.User.Profile,
        () => UserProfilePage(),
        binding: UserProfileBinding(),
      ),
      FRouteSetting(
        RouteNames.User.ReportTemplate,
        () => ReportTemplatePage(),
        binding: ReportTemplateBinding(),
      ),
      FRouteSetting(
        RouteNames.User.ReportTemplateDesigner,
        () => ReportDesignerPage(),
        binding: ReportTemplateBinding(),
      ),
      FRouteSetting(
        RouteNames.User.Setting,
        () => UserSettingPage(),
        binding: HardwareDetectionBinding(),
      ),
      FRouteSetting(
        RouteNames.User.DetectionAssistant,
        () => DetectionAssistantNavigation(),
        binding: HardwareDetectionBinding(),
      ),
      FRouteSetting(
        RouteNames.User.Device,
        () => UserDevicePage(),
        binding: UserDevicerBinding(),
      ),
      FRouteSetting(
        RouteNames.User.Entry,
        () => VocabularyEntryPage(),
        binding: VocabularyEntryBinding(),
      ),
      FRouteSetting(
        RouteNames.User.Center,
        () => UserCenterPage(),
        binding: UserCenterBinding(),
        middlewares: [
          RouteAuthMiddleware(feature: FeatureKeys.OrgPersonnel + "xx")
        ],
      ),
      FRouteSetting(
        RouteNames.User.GroupList,
        () => GroupListPage(),
        binding: GroupBinding(),
      ),
    ]);
  }

  void _buildHomeRoutes() {
    _routes.addAll([
      FRouteSetting(
        RouteNames.Home.Home,
        () => HomePage(),
        binding: HomeBinding(),
      ),
      FRouteSetting(
        RouteNames.Home.Profile,
        () => ProfileCompletePage(),
        binding: ProfileCompleteBinding(),
      ),
      FRouteSetting(
        RouteNames.Home.MainPage,
        () => HomePagePage(),
        binding: HomePageBinding(),
      ),
    ]);
  }

  void _buildAuthRoutes() {
    _routes.addAll([
      FRouteSetting(
        RouteNames.Auth.AuthBoard,
        () => AuthBoardPage(),
        binding: AuthBoardBinding(),
        customTransition: AuthBoardPageTransition(),
        // transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 500),
      ),
      FRouteSetting(
        RouteNames.Auth.SignIn,
        () => SignInPage(),
        binding: SignInBinding(),
        customTransition: FTransitions.sharedAxisHorizontal,
        transitionDuration: const Duration(milliseconds: 300),
      ),
      FRouteSetting(
        RouteNames.Auth.SignUp,
        () => SignUpPage(),
        binding: SignUpBinding(),
        customTransition: FTransitions.sharedAxisHorizontal,
        transitionDuration: const Duration(milliseconds: 300),
      ),
      FRouteSetting(
        RouteNames.Auth.RetrievePwd,
        () => RetrievePasswordPage(),
        binding: RetrievePasswordBinding(),
        customTransition: FTransitions.sharedAxisHorizontal,
        transitionDuration: const Duration(milliseconds: 300),
      ),
    ]);
  }

  void _buildOrgRoutes() {
    _routes.addAll([
      FRouteSetting(
        RouteNames.Org.Info,
        () => OrgInfoPage(),
        binding: OrgInfoBinding(),
      ),
      FRouteSetting(
        RouteNames.Org.Personnel,
        () => OrgPesonnelPage(),
        binding: OrgPesonnelBinding(),
      ),
      FRouteSetting(
        RouteNames.Org.Device,
        () => UserDevicePage(),
        binding: UserDevicerBinding(),
      ),
      FRouteSetting(
        RouteNames.Org.AddDevice,
        () => AddorEditMobileTerminalPage(),
        binding: UserDevicerBinding(),
      ),
      FRouteSetting(
        RouteNames.Org.Entry,
        () => VocabularyEntryPage(),
        binding: VocabularyEntryBinding(),
      ),
      FRouteSetting(
        RouteNames.Org.ReportTemplate,
        () => ReportTemplatePage(),
        binding: ReportTemplateBinding(),
      ),
    ]);
  }

  void _buildRemedicalRoutes() {
    _routes.addAll([
      FRouteSetting(
        RouteNames.Remedical.Consultation,
        () => ConsultationPage(),
        binding: ConsultationBinding(),
      ),
      FRouteSetting(
        RouteNames.Remedical.ConsultationPatientView,
        () => ConsultationPage(),
        binding: ConsultationBinding(),
      ),
      FRouteSetting(
        RouteNames.Remedical.ConsultationRecordView,
        () => ConsultationRecordViewPage(),
        binding: ConsultationRecordViewBinding(),
      ),
      FRouteSetting(
        RouteNames.Remedical.ImagePool,
        () => ImagePoolPage(),
        binding: ImagePoolBinding(),
      ),
      FRouteSetting(
        RouteNames.Remedical.AddOrEditPatirntDiaLog,
        () => AddoreditPatientDialogPage(),
        binding: AddoreditpatirntdialogBinding(),
      ),
      FRouteSetting(
        RouteNames.Remedical.ReportEdit,
        () => ReporteditPage(),
        binding: ReportEditBinding(),
      ),
      FRouteSetting(
        RouteNames.Remedical.ReportPreview,
        () => ReportPreviewPage(),
        binding: ReportPreviewBinding(),
      ),
      FRouteSetting(
        RouteNames.Remedical.Measure,
        () => MeasureHomePage(),
        binding: MeasureHomeBinding(),
      ),
    ]);
  }

  void _buildRealTimeRemedicalRoutes() {
    _routes.addAll([
      FRouteSetting(RouteNames.RealTimeRemedical.RealTimeConsultation,
          () => FRealTimeConsultationListPage(), binding: BindingsBuilder(() {
        Get.lazyPut(() => RealTimeConsultationController());
      })),
      FRouteSetting(
        RouteNames.RealTimeRemedical.CalendarPage,
        () => QuickFWidget(CalendarPage()),
      ),
      // FRouteSetting("/views/desktop/real_time_consultation",
      //     () => ComfirmApplicationPage()),
      FRouteSetting(
        RouteNames.RealTimeRemedical.LiveConsultation,
        () => LiveConsulationPage(),
        binding: LiveConsultationBinding(),
      ),
    ]);
  }

  void _buildLaboratoryRoutes() {
    _routes.addAll([
      FRouteSetting(
        RouteNames.Laboratory.LaboratoryFolder,
        () => LaboratoryPage(),
        // binding: LaboratoryBinding(),
      ),
      FRouteSetting(
        RouteNames.Laboratory.AiLaboratoryFolder,
        () => OverdueUrgeReplyPage(),
        // binding: LaboratoryBinding(),
      ),
      FRouteSetting(
        RouteNames.Laboratory.LaboratoryReportFolder,
        () => LaboratoryReportPage(),
        binding: LaboratoryBinding(),
      ),
    ]);
  }

  void _buildThirdpartyPage() {
    _routes.addAll([
      FRouteSetting(
        RouteNames.Thirdparty.ThirdpartyPage,
        () => ThirdpartyPage(),
        binding: FeedbackBinding(),
      ),
    ]);
  }

  void _buildLiveRoutes() {
    _routes.addAll([
      FRouteSetting(
        RouteNames.Live.DeviceList,
        () => DeviceLiveListDesktopPage(),
        binding: BindingsBuilder(() {
          final controller = DeviceLiveListDesktopController();
          Get.put<DeviceLiveListController>(controller);
          Get.put<DeviceLiveListDesktopController>(controller);
        }),
      ),
      FRouteSetting(
        RouteNames.Live.DeviceDetail,
        () => DeviceLiveDetailDesktopPage(),
        binding: BindingsBuilder(() {
          Get.put(DeviceLiveDetailDesktopController());
        }),
      ),
      FRouteSetting(
        RouteNames.Live.RemoteController,
        () => RemoteControllerPage(),
        binding: BindingsBuilder(() {
          var controller = Get.put(RemoteControllerController());
          controller.ignoreAllGestures = true;
        }),
      ),
    ]);
  }
}

///Fis的路由错误页面配置
class FErrorRouteSettings {
  FErrorRouteSettings._();

  static final NotFount = FRouteSetting(
    RouteNames.Error.NotFound,
    () => NotFoundPage(),
    binding: NotFoundBinding(),
  );
}
