import 'package:auto_route/auto_route.dart';
import 'package:krow/core/application/di/injectable.dart';
import 'package:krow/core/application/routing/guards.dart';
import 'package:krow/core/application/routing/routes.gr.dart';
import 'package:krow/core/sevices/auth_state_service/auth_service.dart';

@AutoRouterConfig()
class AppRouter extends RootStackRouter {
  @override
  RouteType get defaultRouteType => const RouteType.material();

  @override
  List<AutoRoute> get routes => [
        AdaptiveRoute(
          path: '/',
          page: SplashRoute.page,
          initial: true,
          guards: [SplashRedirectGuard(getIt<AuthService>())],
        ),
        authFlow,
        signUnFlow,
        homeBottomBarFlow,
        phoneReLoginFlow,
        checkListFlow,
        AutoRoute(page: WaitingValidationRoute.page),
      ];

  get homeBottomBarFlow => AdaptiveRoute(
      path: '/home',
      page: HomeRoute.page,
      children: [earningsFlow, shiftsFlow, profileFlow]);

  get authFlow => AdaptiveRoute(
        path: '/auth',
        page: AuthFlowRoute.page,
        children: [
          AutoRoute(path: 'welcome', page: WelcomeRoute.page, initial: true),
          AutoRoute(path: 'phone', page: PhoneVerificationRoute.page),
          AutoRoute(path: 'code', page: CodeVerificationRoute.page),
        ],
      );

  get phoneReLoginFlow => AdaptiveRoute(
        path: '/phoneReLogin',
        page: PhoneReLoginFlowRoute.page,
        children: [
          AutoRoute(page: CodeVerificationRoute.page, initial: true),
        ],
      );

  get signUnFlow => AdaptiveRoute(
        path: '/signup',
        page: SignupFlowRoute.page,
        guards: [SingUpRedirectGuard(getIt<AuthService>())],
        children: [
          AutoRoute(page: PersonalInfoRoute.page, initial: true),
          AutoRoute(page: EmailVerificationRoute.page),
          AutoRoute(page: EmergencyContactsRoute.page),
          AutoRoute(page: MobilityRoute.page),
          AutoRoute(page: InclusiveRoute.page),
          AutoRoute(page: AddressRoute.page),
          AutoRoute(page: WorkingAreaRoute.page),
          AutoRoute(page: RoleRoute.page),
        ],
      );

  get checkListFlow => AdaptiveRoute(
        path: '/check_list',
        page: CheckListFlowRoute.page,
        children: [
          AutoRoute(page: CheckListRoute.page, initial: true),
          AutoRoute(page: PersonalInfoRoute.page),
          AutoRoute(page: EmailVerificationRoute.page),
          AutoRoute(page: EmergencyContactsRoute.page),
          AutoRoute(page: AddressRoute.page),
          AutoRoute(page: WorkingAreaRoute.page),
          AutoRoute(page: RoleRoute.page),
          AutoRoute(page: CertificatesRoute.page),
          AutoRoute(page: ScheduleRoute.page),
          bankAccFlow,
          wagesFormFlow,
          roleKitFlow
        ],
      );

  get profileFlow => AdaptiveRoute(
        path: 'profile',
        page: ProfileMainFlowRoute.page,
        children: [
          AutoRoute(path: 'menu', page: ProfileMainRoute.page, initial: true),
          roleKitFlow,
          AutoRoute(path: 'certificates', page: CertificatesRoute.page),
          AutoRoute(path: 'schedule', page: ScheduleRoute.page),
          AutoRoute(path: 'working_area', page: WorkingAreaRoute.page),
          AutoRoute(path: 'live_photo', page: LivePhotoRoute.page),
          profileSettingsFlow,
          wagesFormFlow,
          bankAccFlow,
          AutoRoute(path: 'benefits', page: BenefitsRoute.page),
          AutoRoute(path: 'support', page: SupportRoute.page),
          AutoRoute(path: 'faq', page: FaqRoute.page),
        ],
      );

  get bankAccFlow =>
      AutoRoute(path: 'bank', page: BankAccountFlowRoute.page, children: [
        AutoRoute(path: 'info', page: BankAccountRoute.page, initial: true),
        AutoRoute(path: 'edit', page: BankAccountEditRoute.page),
      ]);

  get wagesFormFlow => AutoRoute(
        path: 'wages_form',
        page: WagesFormsFlowRoute.page,
        children: [
          AutoRoute(path: 'list', page: FormsListRoute.page, initial: true),
          AutoRoute(path: 'offerLatter', page: OfferLetterFormRoute.page),
          AutoRoute(path: 'edd', page: EddFormRoute.page),
          AutoRoute(path: 'i-9', page: INineFormRoute.page),
          AutoRoute(path: 'w-4', page: WFourFormRoute.page),
          AutoRoute(path: 'sign', page: FormSignRoute.page),
          AutoRoute(path: 'signedForm', page: SignedFormRoute.page),
          AutoRoute(path: 'preview', page: FormPreviewRoute.page),
        ],
      );

  get profileSettingsFlow => AutoRoute(
        path: 'profile_settings',
        page: ProfileSettingsFlowRoute.page,
        children: [
          AutoRoute(
            path: 'menu',
            page: ProfileSettingsMenuRoute.page,
            initial: true,
          ),
          AutoRoute(path: 'role', page: RoleRoute.page),
          AutoRoute(path: 'personal', page: PersonalInfoRoute.page),
          AutoRoute(
            page: EmailVerificationRoute.page,
            path: 'emailVerification',
          ),
          AutoRoute(path: 'address', page: AddressRoute.page),
          AutoRoute(path: 'emergency', page: EmergencyContactsRoute.page),
          AutoRoute(path: 'mobility', page: MobilityRoute.page),
          AutoRoute(path: 'inclusive', page: InclusiveRoute.page),
        ],
      );

  get roleKitFlow => AutoRoute(
        path: 'role_kit',
        page: RoleKitFlowRoute.page,
        children: [
          AutoRoute(path: 'list', page: RolesKitListRoute.page, initial: true),
          AutoRoute(path: 'details', page: RoleKitRoute.page),
        ],
      );

  get earningsFlow => AdaptiveRoute(
        path: 'earnings',
        page: EarningsFlowRoute.page,
        children: [
          AutoRoute(path: 'list', page: EarningsRoute.page, initial: true),
          AutoRoute(path: 'history', page: EarningsHistoryRoute.page),
        ],
      );

  get shiftsFlow => AdaptiveRoute(
        path: 'shifts',
        initial: true,
        page: ShiftsFlowRoute.page,
        children: [
          AdaptiveRoute(
            path: 'list',
            page: ShiftsListMainRoute.page,
            initial: true,
          ),
          AdaptiveRoute(path: 'details', page: ShiftDetailsRoute.page),
          AdaptiveRoute(path: 'scanner', page: QrScannerRoute.page)
        ],
      );

  @override
  List<AutoRouteGuard> get guards => [];
}
