import 'package:mc_common_app/models/advertisment_models/ad_details_model.dart';
import 'package:mc_common_app/models/chat_models/buyers_chat_for_ads_model.dart';
import 'package:mc_common_app/models/chat_models/chat_message_model.dart';
import 'package:mc_common_app/models/requests_models/provider_offers_model.dart';
import 'package:mc_common_app/models/requests_models/request_model.dart';
import 'package:mc_common_app/models/user_models/register_user.dart';
import 'package:mc_common_app/utils/enums.dart';
import 'package:mc_common_app/views/advertisement/ads_buyer_chats_view.dart';
import 'package:mc_common_app/views/advertisement/ads_detail_view/ads_detail_view.dart';
import 'package:mc_common_app/views/advertisement/ads_filter_view.dart';
import 'package:mc_common_app/views/advertisement/create_ad_view.dart';
import 'package:mc_common_app/views/advertisement/select_ad_type_view.dart';
import 'package:mc_common_app/views/chat/chat_view.dart';
import 'package:mc_common_app/views/payments/payment_methods_view.dart';
import 'package:mc_common_app/views/profile/profile_view.dart';
import 'package:mc_common_app/views/requests/create_request_page.dart';
import 'package:mc_common_app/views/requests/offer_list_page.dart';
import 'package:mc_common_app/views/requests/request_detail_page.dart';
import 'package:mc_common_app/views/requests/requests_filter_view.dart';
import 'package:mc_common_app/views/requests/review_request_offer.dart';
import 'package:mc_common_app/views/setting_options/provider_accepted_requests_view.dart';
import 'package:mc_common_app/views/setting_options/provider_license_page.dart';
import 'package:mc_common_app/views/setting_options/setting_option_help.dart';
import 'package:mc_common_app/views/setting_options/setting_options_app_info.dart';
import 'package:mc_common_app/views/setting_options/setting_options_contact_us.dart';
import 'package:mc_common_app/views/setting_options/setting_options_faqs.dart';
import 'package:mc_common_app/views/setting_options/setting_options_invite_friends.dart';
import 'package:mc_common_app/views/setting_options/setting_options_more.dart';
import 'package:mc_common_app/views/setting_options/setting_options_terms_and_conditions.dart';
import 'package:mc_common_app/views/shipping_management/shipping_management_view.dart';
import 'package:mc_common_app/views/user/change_email_page.dart';
import 'package:mc_common_app/views/user/change_mobile_page.dart';
import 'package:mc_common_app/views/user/change_password_page.dart';
import 'package:mc_common_app/views/user/complete_profile_page.dart';
import 'package:mc_common_app/views/user/confirm_new_password_page.dart';
import 'package:mc_common_app/views/user/edit_account_page.dart';
import 'package:mc_common_app/views/user/forget_password_method_page.dart';
import 'package:mc_common_app/views/user/forget_password_page.dart';
import 'package:mc_common_app/views/user/login_method_selection_page.dart';
import 'package:mc_common_app/views/user/login_verification_page.dart';
import 'package:mc_common_app/views/user/login_verify_account_page.dart';
import 'package:mc_common_app/views/user/login_with_password_page.dart';
import 'package:mc_common_app/views/user/register_page.dart';
import 'package:mc_common_app/views/user/register_provider_page.dart';
import 'package:mc_common_app/views/user/register_selection_page.dart';
import 'package:mc_common_app/views/splash/splash_page.dart';
import 'package:mc_common_app/views/user/vertify_password_page.dart';
import 'package:flutter/material.dart';
import 'package:mc_common_app/widgets/image_viewer/image_viewer_screen.dart';

class AppRoutes {
  //User
  static const String splash = "/splash";
  static const String registerSelection = "/registerSelection";
  static const String loginVerifyAccount = "/loginVerifyAccount";
  static const String registerCustomer = "/registerCustomer";
  static const String registerProvider = "/registerProvider";
  static const String forgetPassword = "/forgetPassword";
  static const String loginVerification = "/loginVerification";
  static const String loginWithPassword = "/loginWithPassword";
  static const String loginMethodSelection = "/loginMethodSelection";
  static const String completeProfile = "/completeProfile";
  static const String profile1 = "/profile1";
  static const String profile2 = "/profile2";
  static const String profile3 = "/profile3";
  static const String verifyPassword = "/vertifyPassword";
  static const String confirmNewPasswordPage = "/confirmNewPasswordPage";
  static const String changePassword = "/changePassword";
  static const String forgetPasswordMethodPage = "/forgetPasswordMethodPage";
  static const String changeMobilePage = "/changeMobilePage";
  static const String changeEmailPage = "/changeEmailPage";
  static const String editAccountPage = "/editAccoundPage";

  // Provider App Routes

  //settings
  static const defineLicense = "/defineLicese";
  static const String dealershipSetting = "/dealershipSetting";
  static const String branchList = "/branchList";
  static const String branchDetail = "/branchDetail";
  static const String defineBranch = "/defineBranch";

  //Appointments
  static const String appointment = "/appointment";
  static const String appointmentDetailList = "/appointmentDetailList";
  static const String updateAppointmentPage = "/updateAppointmentPage";
  static const String addServiceInAppointment = "/addServiceInAppointment";
  static const String mergeAppointments = "/mergeAppointments";

  //Services
  static const String dealerUser = "/dealerUser";
  static const String servicesList = "/servicesList";
  static const String itemsList = "/itemsList";
  static const String createItem = "/createItem";
  static const String createServices = "/createServices";
  static const String createServices2 = "/createServices2";
  static const String createServices3 = "/createServices3";

  //Schedules
  static const String schedulesList = "/schedulesList";
  static const String addSchedule = "/addSchedule";

  // Subscriptions
  static const String mySubscriptionsPage = "/mySubscriptionsPage";
  static const String subscriptionsPage = "/subscriptionsPage";

  //Bracnh Duplication
  static const String matchServices = "/matchServices";
  static const String userSettings = "/userSettings";

  static const String dashboard = "/dashboard";
  static const String bookProviderAppView = "/bookProviderAppView";

  // Appointments
  static const String appointmentDetailView = "/appointmentDetailView";
  static const String bookAppointmenServicesView = "/bookAppointmenServicesView";
  static const String bookAppointmenSchedulesView = "/bookAppointmenSchedulesView";
  static const String bookAppointmentsItemView = "/bookAppointmentsItemView";
  static const String reviewAppointmentView = "/reviewAppointmentView";
  static const String appoinmentSearchFilterPage = "/appoinmentSearchFilterPage";

  //Advertisement
  static const String selectAdTypeView = "/selectAdTypeView";
  static const String adsDetailView = "/adsDetailView";
  static const String createAdView = "/createAdView";
  static const String adsFilterView = "/adsFilterView";
  static const String adsBuyerChatsListView = "/adsBuyersChatListView";

  // Payments
  static const String paymentMethodsView = "/paymentMethodsView";

  //Shipping
  static const shippingManagementView = "/shippingManagementView";

  //Customer APP: Provider & Services
  static const String branchDetailView = "/branchDetailPage";
  static const String branchSearchFilterPage = "/branchSearchFilterPage";
  static const String providerProfileView = "/providerProfilePage";
  static const String favoriteListView = "/favoriteListView";

  //Requests
  static const String requestsDetailPage = "/requestsDetailPage";
  static const String sendOfferPage = "/sendOfferPage";
  static const String myRequestsPage = "/myRequestsPage";
  static const String requestsFilterView = "/requestsFilterView";
  static const String createRequestPage = "/createRequestPage";
  static const String offersListPage = "/offersListPage";
  static const String reviewRequestOffer = "/reviewRequestOffer";
  static const String providerAcceptedRequestsView = "/providerAcceptedRequestsView";

  //Setting Options
  static const String settingOptionsFaqs = "/settingOptionsFaqs";
  static const String settingOptionsContactUs = "/settingOptionsContactUs";
  static const String settingOptionsAppInfo = "/settingOptionsAppInfo";
  static const String settingOptionsTermsAndConditions = "/settingOptionsTermsAndConditions";
  static const String settingOptionsMore = "/settingOptionsLanguages";
  static const String settingOptionsInviteFriends = "/settingOptionsInviteFriends";
  static const String settingOptionsHelp = "/settingOptionsHelp";

  //MediaViewer
  static const String mediaViewerScreen = "/mediaViewer";

  //Profile Screen
  static const String profileView = "/profileView";
  static const providerLicensePage = "/providerLicensePage";

  static const String generalChatsListForProvider = "/generalChatsListForProvider";

  //Chat
  static const String chatView = "/chatView";
  static const String initialRoute = splash;

  static final Map<String, WidgetBuilder> routes = {
    //User
    splash: (context) => const SplashPage(),
    registerSelection: (context) => const RegisterSelectionPage(),
    loginVerifyAccount: (context) => LoginVerifyAccountPage(),
    registerCustomer: (context) => const RegisterCustomerPage(),
    registerProvider: (context) => const RegisterProviderPage(),
    forgetPassword: (context) => const ForgetPasswordPage(),
    loginVerification: (context) => const LoginVerificationPage(),
    loginWithPassword: (context) => const LoginWithPassword(),
    loginMethodSelection: (context) => LoginMethodSelectionPage(ModalRoute.of(context)!.settings.arguments as String),
    completeProfile: (context) => CompleteProfilePage(ModalRoute.of(context)!.settings.arguments as RegisterUserRespModel),
    verifyPassword: (context) => VerifyPasswordPage(),
    confirmNewPasswordPage: (context) => ConfirmNewPasswordPage(ModalRoute.of(context)!.settings.arguments as String),
    forgetPasswordMethodPage: (context) => ForgetPasswordMethodPage(ModalRoute.of(context)!.settings.arguments as String),
    changeMobilePage: (context) => ChangeMobilePage(),
    changeEmailPage: (context) => const ChangeEmailPage(),
    changePassword: (context) => const ChangePasswordPage(),
    editAccountPage: (context) => const EditAccountPage(),
    profileView: (context) => const ProfileScreen(),
    settingOptionsMore: (context) => const SettingOptionsMore(),
    settingOptionsHelp: (context) => const SettingOptionsHelp(),
    providerLicensePage: (context) => const ProviderLicensePage(),

    // common pages
    AppRoutes.adsDetailView: (context) => AdsDetailView(adDetails: ModalRoute.of(context)!.settings.arguments as AdDetailsModel),
    AppRoutes.createAdView: (context) => const CreateAdView(),
    AppRoutes.adsFilterView: (context) => const AdsFilterView(),
    AppRoutes.selectAdTypeView: (context) => SelectAdTypeView(arguments: ModalRoute.of(context)!.settings.arguments as List<dynamic>),
    AppRoutes.chatView: (context) => ChatView(chatViewArguments: ModalRoute.of(context)!.settings.arguments as ChatViewArguments),
    AppRoutes.adsBuyerChatsListView: (context) => AdsBuyerChatsView(buyersListViewArguments: ModalRoute.of(context)!.settings.arguments as List<BuyersChatForAdsModel>),
    AppRoutes.settingOptionsFaqs: (context) => const SettingOptionsFAQs(),
    AppRoutes.settingOptionsContactUs: (context) => const SettingOptionsContactUs(),
    AppRoutes.settingOptionsAppInfo: (context) => const SettingOptionsAppInfo(),
    AppRoutes.settingOptionsTermsAndConditions: (context) => const SettingOptionsTermsAndConditions(),
    AppRoutes.settingOptionsInviteFriends: (context) => const SettingOptionsInviteFriends(),
    AppRoutes.paymentMethodsView: (context) => PaymentMethodsView(paymentType: ModalRoute.of(context)!.settings.arguments as PaymentTypes),
    //Requests
    AppRoutes.requestsDetailPage: (context) => RequestDetailPage(requestDetailPageArguments: ModalRoute.of(context)!.settings.arguments as RequestDetailPageArguments),
    AppRoutes.createRequestPage: (context) => const CreateRequestPage(),
    AppRoutes.offersListPage: (context) => OfferListPage(requestId: ModalRoute.of(context)!.settings.arguments as int),
    AppRoutes.reviewRequestOffer: (context) => const ReviewRequestOffer(),
    AppRoutes.requestsFilterView: (context) => const RequestsFilterView(),

    //MediaViewer
    AppRoutes.mediaViewerScreen: (context) => MediaViewerScreen(images: ModalRoute.of(context)!.settings.arguments as List<MessageImageModel>),

    // ChatsList Provider
    AppRoutes.generalChatsListForProvider: (context) => OfferListPage(requestId: ModalRoute.of(context)!.settings.arguments as int),

    //Shipping
    AppRoutes.shippingManagementView: (context) => const ShippingManagementView(),
  };
}

class ChatViewArgumentsForRequest {
  final int? requestId;
  final ChatTypeEnum chatTypeEnum;
  final String senderId;
  final String receiverId;
  final int providerIndex;
  final int requestIndex;
  final RequestModel? requestModel;

  ChatViewArgumentsForRequest({
    required this.chatTypeEnum,
    this.requestId,
    required this.senderId,
    required this.receiverId,
    required this.providerIndex,
    required this.requestIndex,
    this.requestModel,
  });
}

class ChatViewArgumentsForAd {
  final String? receiverUserID;
  final int? adsID;

  ChatViewArgumentsForAd({required this.receiverUserID, required this.adsID});
}

class ChatViewArguments {
  final ChatViewArgumentsForAd? chatViewArgumentsForAd;
  final ChatViewArgumentsForRequest? chatViewArgumentsForRequest;
  final ChatTypeEnum chatTypeEnum;

  ChatViewArguments({
    this.chatViewArgumentsForAd,
    this.chatViewArgumentsForRequest,
    required this.chatTypeEnum,
  });
}

class OfferListPageArguments {
  final List<ServiceProvidersOffers> serviceProviderOffers;
  final int? requestId;

  OfferListPageArguments({required this.serviceProviderOffers, this.requestId});
}

class RequestDetailPageArguments {
  final int requestIndex;
  final RequestModel requestModel;

  RequestDetailPageArguments({required this.requestIndex, required this.requestModel});
}
