part of routes;

abstract class Routes {
  static final RouteObserver<Route> observer = RouteObservers();
  static List<String> history = [];

  static const splash = 'splash';
  static const main = 'main';
  static const ad = 'ad';

  static const web = 'read_web';

  // 支付界面
  static const bookPay = 'book_pay';
  // 用户协议 和 隐私政策
  static const terms = 'terms';
  // 搜索
  static const search = 'search';


  /// 登录模块
  // 登录
  static const login = 'login';
  // 忘记密码
  static const forgetPwd = 'forget_pwd';
  // 重置密码
  static const resetPwd = 'reset_pwd';


  /// 课程模块
  // 详情
  static const bookDetail = 'book_detail';
  // 评分及书评
  static const bookScore = 'book_score';
  // 学习报告
  static const studyReport = 'study_report';


  /// 图书馆模块
  // 百科
  static const baiKe = 'bai_ke';


  /// 书架模块
  static const creditPoints = 'credit_points';
  static const shop = 'shop';
  static const payCoupon = 'pay_coupon';



  /// 我的模块
  // 个人信息
  static const userInfo = 'user_info';
  // 修改昵称
  static const nike = 'nike';
  // 性别
  static const gender = 'gender';
  // 设置
  static const set = 'set';
  // 版本
  static const version = 'version';
  // 版本介绍
  static const versionDes = 'version_des';
  // 我的收藏
  static const collect = 'collect';
  // 紫金币记录
  static const coin = 'coin';
  // 积分记录
  static const point = 'point';
  // 消息
  static const msgs = 'msgs';
  // 关于
  static const about = 'user_about';
  // 最近学习
  static const studyHistory = 'study_history';
  // 我的收藏
  static const love = 'love';
  // 笔记
  static const note = 'note';
  // 笔记详情
  static const noteDes = 'note_des';
  // 错题
  static const wrong = 'wrong';
  // 讨论
  static const discuss = 'discuss';
  // 讨论详情
  static const discussDes = 'discuss_des';
  // 优惠券
  static const coupon = 'coupon';
  // 账号安全
  static const security = 'security';
  // 修改手机号
  static const changePhone = 'change_change';
  // 修改密码
  static const changePwd = 'change_pwd';
  // 意见反馈
  static const feedback = 'feedback';
  // 订单评价
  static const orderEvaluate= 'order_evaluate';
  // 帮助中心
  static const helpCenter= 'help_center';
  // 帮助中心内容
  static const helpCenterContent = 'help_center_content';
  // 订单列表
  static const order= 'order';
  // 已完成订单
  static const orderCompleted= 'order_completed';
  // 待付款订单
  static const orderAwaiting= 'order_awaiting';
  // 已退款订单
  static const orderRefunded= 'order_refunded';




  static final GoRouter config = GoRouter(
      // initialLocation: '/$splash',
      initialLocation: '/',
      observers: [observer],
      // redirect: _RouteRedirect.auth,
      routes: [
        GoRoute(
            path: '/$splash',
            name: splash,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const SplashPage(),
            ),
        ),
        GoRoute(
            path: '/',
            name: main,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const MainPage()
            )
        ),
        GoRoute(
            path: '/$ad',
            name: ad,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const AdPage()
            )
        ),
        /// 登录模块
        GoRoute(
            path: '/$login',
            name: login,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const LoginPage()
            )
        ),
        GoRoute(
            path: '/$forgetPwd',
            name: forgetPwd,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const ForgetPwdPage()
            )
        ),
        GoRoute(
            path: '/$resetPwd',
            name: resetPwd,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: ResetPwdPage(
                  phone: state.uri.queryParameters['phone'].toString(),
                  code: state.uri.queryParameters['code'].toString(),
                )
            )
        ),
        GoRoute(
            path: '/$web',
            name: web,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: ReadPage(
                  bookId: state.uri.queryParameters['book_id'].toString(),
                  chapterId: state.uri.queryParameters['chapter_id'].toString(),
                  chapterName: state.uri.queryParameters['chapter_name'].toString(),
                )
            )
        ),
        GoRoute(
            path: '/$about',
            name: about,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const AboutPage()
            )
        ),
        GoRoute(
            path: '/$bookPay',
            name: bookPay,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: BookPayPage(buy: state.extra as List<CourseModel>,)
            )
        ),
        GoRoute(
            path: '/$terms',
            name: terms,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const TermsPage()
            )
        ),
        GoRoute(
            path: '/$msgs',
            name: msgs,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const MsgPage()
            )
        ),
        GoRoute(
            path: '/$userInfo',
            name: userInfo,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: UserInfoPage(userInfo: state.extra as UserInfoModel,)
            )
        ),
        GoRoute(
            path: '/$nike',
            name: nike,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: UserNickPage(userInfo: state.extra as UserInfoModel,)
            )
        ),
        GoRoute(
            path: '/$coin',
            name: coin,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserCoinPage()
            )
        ),
        GoRoute(
            path: '/$bookDetail',
            name: bookDetail,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: BookDetailPage(
                  bookId: state.uri.queryParameters['book_id'].toString(),
                )
            )
        ),
        GoRoute(
            path: '/$bookScore',
            name: bookScore,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: BookScorePage(
                  bookId: state.uri.queryParameters['book_id'].toString(),
                )
            )
        ),
        GoRoute(
            path: '/$studyReport',
            name: studyReport,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: StudyReportPage(
                  bookId: state.uri.queryParameters['book_id'].toString(),
                )
            )
        ),
        GoRoute(
            path: '/$creditPoints',
            name: creditPoints,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const CreditPointsPage()
            )
        ),
        GoRoute(
            path: '/$payCoupon',
            name: payCoupon,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: PayCouponPage(
                  payController: state.extra as BookPayController,
                )
            )
        ),
        GoRoute(
            path: '/$search',
            name: search,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const SearchPage()
            )
        ),
        GoRoute(
            path: '/$studyHistory',
            name: studyHistory,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const StudyHistoryPage()
            )
        ),
        GoRoute(
            path: '/$love',
            name: love,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserLovePage()
            )
        ),
        GoRoute(
            path: '/$shop',
            name: shop,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const BookShopPage()
            )
        ),
        GoRoute(
            path: '/$note',
            name: note,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserNotePage()
            )
        ),
        GoRoute(
            path: '/$wrong',
            name: wrong,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserWrongPage()
            )
        ),
        GoRoute(
            path: '/$point',
            name: point,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserPointPage()
            )
        ),
        GoRoute(
            path: '/$discuss',
            name: discuss,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserDiscussPage()
            )
        ),
        GoRoute(
            path: '/$coupon',
            name: coupon,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserCouponPage()
            )
        ),
        GoRoute(
            path: '/$set',
            name: set,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserSetPage()
            )
        ),
        GoRoute(
            path: '/$version',
            name: version,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const VersionPage()
            )
        ),
        GoRoute(
            path: '/$versionDes',
            name: versionDes,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: VersionDesPage(model: state.extra as VersionModel,)
            )
        ),
        GoRoute(
            path: '/$security',
            name: security,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: UserSecurityPage(model: state.extra as UserInfoModel,)
            )
        ),
        GoRoute(
            path: '/$changePhone',
            name: changePhone,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const ChangePhonePage()
            )
        ),
        GoRoute(
            path: '/$changePwd',
            name: changePwd,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: ChangePwdPage(userInfo: state.extra as UserInfoModel)
            )
        ),
        GoRoute(
            path: '/$feedback',
            name: feedback,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserFeedbackPage()
            )
        ),
        GoRoute(
            path: '/$noteDes',
            name: noteDes,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: UserNotesDesPage(model: state.extra as CourseModel,)
            )
        ),
        GoRoute(
            path: '/$gender',
            name: gender,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: UserGenderPage(userInfo: state.extra as UserInfoModel,)
            )
        ),
        GoRoute(
            path: '/$discussDes',
            name: discussDes,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: UserDiscussDesPage(model: state.extra as CourseModel,)
            )
        ),
        GoRoute(
            path: '/$orderEvaluate',
            name: orderEvaluate,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserOrderEvaluatePage()
            )
        ),
        GoRoute( // 帮助中心
            path: '/$helpCenter',
            name: helpCenter,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const HelpCenterPage()
            )
        ),
        GoRoute( // 帮助中心内容
            path: '/$helpCenterContent',
            name: helpCenterContent,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: HelpCenterContentPage(id: state.uri.queryParameters['id'].toString())
            )
        ),
        GoRoute( // 已完成订单
            path: '/$order',
            name: order,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserOrderPage()
            )
        ),
        GoRoute( // 已完成订单
            path: '/$orderCompleted',
            name: orderCompleted,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserOrderCompletedPage()
            )
        ),
        GoRoute( // 待付款订单
            path: '/$orderAwaiting',
            name: orderAwaiting,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserOrderAwaitingPage()
            )
        ),
        GoRoute( // 已退款订单
            path: '/$orderRefunded',
            name: orderRefunded,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: const UserOrderRefundedPage()
            )
        ),
        GoRoute( // 百科
            path: '/$baiKe',
            name: baiKe,
            pageBuilder: (context, state) =>CupertinoPage(
                name: state.uri.toString(),
                key: state.pageKey,
                child: BaiKePage(
                  keyword: state.uri.queryParameters['keyword'].toString(),
                )
            )
        ),
      ]
  );

}

abstract class _RouteRedirect {
  static String? auth(BuildContext context, GoRouterState state) {
    if (UserStore.to.isLogin) return null;
    return '/${Routes.login}';
  }
}