import type {
  ApiAiComposeTone,
  ApiAiComposeToneExample,
  ApiAttachBot,
  ApiBirthday,
  ApiBoost,
  ApiBoostsStatus,
  ApiChannelMonetizationStatistics,
  ApiChannelStatistics,
  ApiChatInviteInfo,
  ApiChatlistInvite,
  ApiChatType,
  ApiCheckedGiftCode,
  ApiCollectibleInfo,
  ApiComposedMessageWithAI,
  ApiDialog,
  ApiEmojiStatusCollectible,
  ApiFormattedText,
  ApiGeoPoint,
  ApiGlobalMessageSearchType,
  ApiGroupStatistics,
  ApiInputAiComposeTone,
  ApiInputInvoice,
  ApiLimitTypeWithModal,
  ApiMessage,
  ApiMissingInvitedUser,
  ApiMyBoost,
  ApiNewMediaTodo,
  ApiNewPoll,
  ApiNotification,
  ApiPaymentFormRegular,
  ApiPaymentFormStars,
  ApiPaymentStatus,
  ApiPhoneCall,
  ApiPostStatistics,
  ApiPremiumGiftCodeOption,
  ApiPremiumPromo,
  ApiPremiumSection,
  ApiPreparedInlineMessage,
  ApiReactionWithPaid,
  ApiReceiptRegular,
  ApiSavedGifts,
  ApiSavedStarGift,
  ApiSearchPostsFlood,
  ApiSponsoredPeer,
  ApiStarGift,
  ApiStarGiftAttribute,
  ApiStarGiftAttributeCounter,
  ApiStarGiftAttributeOriginalDetails,
  ApiStarGiftAuctionAcquiredGift,
  ApiStarGiftUnique,
  ApiStarGiftUpgradePrice,
  ApiStarGiveawayOption,
  ApiStarsSubscription,
  ApiStarsTransaction,
  ApiStarTopupOption,
  ApiSticker,
  ApiThumbnail,
  ApiTypeCurrencyAmount,
  ApiTypePrepaidGiveaway,
  ApiTypeStoryView,
  ApiUniqueStarGiftValueInfo,
  ApiUrlAuthResultRequest,
  ApiUser,
  ApiVideo,
} from '../../api/types';
import type { FoldersActions } from '../../hooks/reducers/useFoldersReducer';
import type { ReducerAction } from '../../hooks/useReducer';
import type {
  ActiveDownloads,
  ActiveEmojiInteraction,
  AudioOrigin,
  ChatCreationProgress,
  ChatMediaSearchParams,
  ChatRequestedTranslations,
  ConfettiStyle,
  FocusDirection,
  GiftProfileFilterOptions,
  GlobalSearchContent,
  IAnchorPosition,
  InlineBotSettings,
  LeftColumnContent,
  ManagementProgress,
  ManagementState,
  MediaViewerMedia,
  MediaViewerOrigin,
  MessageList,
  MessageListType,
  MiddleSearchParams,
  NewChatMembersProgress,
  PaymentStep,
  ProfileEditProgress,
  ProfileTabType,
  ResaleGiftsFilterOptions,
  ScrollTargetPosition,
  SettingsScreens,
  SharedMediaType,
  ShippingOption,
  StarGiftInfo,
  StoryViewerOrigin,
  TabThread,
  ThreadId,
} from '../../types';
import type { WebApp, WebAppModalStateType } from '../../types/webapp';
import type { SearchResultKey } from '../../util/keys/searchResultKey';
import type { RegularLangFnParameters } from '../../util/localization';
import type { ProfileCollectionKey } from '../selectors/payments';
import type { CallbackAction } from './actions';

export type PollVote = {
  peerId: string;
  date: number;
};

export type AiEditorTabBase = {
  isLoading?: boolean;
  result?: ApiComposedMessageWithAI;
  error?: 'floodPremium' | 'aiError' | 'generic';
};

export type TabState = {
  id: number;
  isBlurred?: boolean;
  isMasterTab: boolean;
  inactiveReason?: 'auth' | 'otherClient';
  shouldPreventComposerAnimation?: boolean;
  inviteHash?: string;
  canInstall?: boolean;
  isStatisticsShown?: boolean;
  isLeftColumnShown: boolean;
  newChatMembersProgress?: NewChatMembersProgress;
  uiReadyState: 0 | 1 | 2;
  shouldInit: boolean;
  shouldSkipHistoryAnimations?: boolean;

  gifSearch: {
    query?: string;
    offset?: string;
    results?: ApiVideo[];
  };

  stickerSearch: {
    query?: string;
    hash?: string;
    resultIds?: string[];
  };

  shouldCloseRightColumn?: boolean;
  chatInfo: {
    isOpen: boolean;
    profileTab?: ProfileTabType;
    forceScrollProfileTab?: boolean;
    isOwnProfile?: boolean;
  };
  nextFoldersAction?: ReducerAction<FoldersActions>;
  shareFolderScreen?: {
    folderId: number;
    isFromSettings?: boolean;
    url?: string;
    isLoading?: boolean;
  };

  isCallPanelVisible?: boolean;
  multitabNextAction?: CallbackAction;
  ratingPhoneCall?: ApiPhoneCall;

  messageLists: MessageList[];

  contentToBeScheduled?: {
    gif?: ApiVideo;
    sticker?: ApiSticker;
    poll?: ApiNewPoll;
    todo?: ApiNewMediaTodo;
    isSilent?: boolean;
    sendGrouped?: boolean;
    sendCompressed?: boolean;
    isInvertedMedia?: true;
  };

  activeChatFolder: number;
  tabThreads: Record<string, Record<ThreadId, TabThread>>;
  forumPanelChatId?: string;

  focusedMessage?: {
    chatId?: string;
    threadId?: ThreadId;
    messageId?: number;
    direction?: FocusDirection;
    noHighlight?: boolean;
    isResizingContainer?: boolean;
    quote?: string;
    quoteOffset?: number;
    scrollTargetPosition?: ScrollTargetPosition;
  };

  selectedMessages?: {
    chatId: string;
    messageIds: number[];
  };

  chatInviteModal?: {
    hash: string;
    inviteInfo: ApiChatInviteInfo;
  };

  seenByModal?: {
    chatId: string;
    messageId: number;
  };

  privacySettingsNoticeModal?: {
    chatId: string;
    isReadDate: boolean;
  };

  reactorModal?: {
    chatId: string;
    messageId: number;
  };

  aboutAdsModal?: {
    randomId: string;
    canReport?: boolean;
    sponsorInfo?: string;
    additionalInfo?: string;
  };

  reactionPicker?: {
    chatId?: string;
    messageId?: number;
    storyPeerId?: string;
    storyId?: number;
    position?: IAnchorPosition;
    sendAsMessage?: boolean;
    isForEffects?: boolean;
  };

  shouldPlayEffectInComposer?: true;

  recoveryEmail?: string;

  inlineBots: {
    isLoading: boolean;
    byUsername: Record<string, false | InlineBotSettings>;
  };

  savedGifts: {
    collectionsByPeerId: Record<string, Record<ProfileCollectionKey, ApiSavedGifts>>;
    activeCollectionByPeerId: Record<string, number | undefined>;
    filter: GiftProfileFilterOptions;
  };

  resaleGifts: {
    giftId?: string;
    gifts: ApiStarGift[];
    count: number;
    attributes?: ApiStarGiftAttribute[];
    counters?: ApiStarGiftAttributeCounter[];
    nextOffset?: string;
    attributesHash?: string;
    isLoading?: boolean;
    isAllLoaded?: boolean;
    filter: ResaleGiftsFilterOptions;
    updateIteration: number;
  };

  leftColumn: {
    contentKey: LeftColumnContent;
    settingsScreen: SettingsScreens;
  };

  globalSearch: {
    query?: string;
    minDate?: number;
    maxDate?: number;
    currentContent?: GlobalSearchContent;
    chatId?: string;
    foundTopicIds?: number[];
    sponsoredPeer?: ApiSponsoredPeer;
    searchFlood?: ApiSearchPostsFlood;
    fetchingStatus?: {
      chats?: boolean;
      messages?: boolean;
      botApps?: boolean;
      publicPosts?: boolean;
    };
    isClosing?: boolean;
    localResults?: {
      peerIds?: string[];
    };
    globalResults?: {
      peerIds?: string[];
    };
    popularBotApps?: {
      peerIds: string[];
      nextOffset?: string;
    };
    resultsByType?: Partial<Record<ApiGlobalMessageSearchType, {
      totalCount?: number;
      nextOffsetId?: number;
      nextOffsetPeerId?: string;
      nextOffsetRate?: number;
      foundIds: SearchResultKey[];
    }>>;
  };

  userSearch: {
    query?: string;
    fetchingStatus?: boolean;
    localUserIds?: string[];
    globalUserIds?: string[];
  };

  activeEmojiInteractions?: ActiveEmojiInteraction[];
  activeReactions: Record<string, ApiReactionWithPaid[]>;

  middleSearch: {
    byChatThreadKey: Record<string, MiddleSearchParams | undefined>;
  };

  sharedMediaSearch: {
    byChatThreadKey: Record<string, {
      currentType?: SharedMediaType;
      resultsByType?: Partial<Record<SharedMediaType, {
        totalCount?: number;
        nextOffsetId: number;
        foundIds: number[];
      }>>;
    }>;
  };

  chatMediaSearch: {
    byChatThreadKey: Record<string, ChatMediaSearchParams>;
  };

  management: {
    progress?: ManagementProgress;
    byChatId: Record<string, ManagementState>;
  };

  isPaymentMessageConfirmDialogOpen: boolean;

  storyViewer: {
    isRibbonShown?: boolean;
    isArchivedRibbonShown?: boolean;
    peerId?: string;
    storyId?: number;
    isMuted: boolean;
    isSinglePeer?: boolean;
    isSingleStory?: boolean;
    isPrivate?: boolean;
    isArchive?: boolean;
    // Last viewed story id in current view session.
    // Used for better switch animation between peers.
    lastViewedByPeerId?: Record<string, number>;
    isPrivacyModalOpen?: boolean;
    isPaymentConfirmDialogOpen?: boolean;
    viewModal?: {
      storyId: number;
      views?: ApiTypeStoryView[];
      nextOffset?: string;
      isLoading?: boolean;
    };
    origin?: StoryViewerOrigin;
    // Copy of story list for current view session
    storyList?: {
      peerIds: string[];
      storyIdsByPeerId: Record<string, number[]>;
    };
  };
  storyStealthModal?: {
    targetPeerId: string;
  } | Record<string, never>;

  selectedStoryAlbumId?: number;

  mediaViewer: {
    chatId?: string;
    threadId?: ThreadId;
    messageId?: number;
    withDynamicLoading?: boolean;
    mediaIndex?: number;
    isAvatarView?: boolean;
    isSponsoredMessage?: boolean;
    standaloneMedia?: MediaViewerMedia[];
    origin?: MediaViewerOrigin;
    volume: number;
    playbackRate: number;
    isMuted: boolean;
    isHidden?: boolean;
    timestamp?: number;
  };

  audioPlayer: {
    chatId?: string;
    messageId?: number;
    threadId?: ThreadId;
    origin?: AudioOrigin;
    playbackRate: number;
    isPlaybackRateActive?: boolean;
    timestamp?: number;
    isMuted: boolean;
  };

  webPagePreviewId?: string;

  loadingThread?: {
    loadingChatId: string;
    loadingMessageId: number;
  };

  isShareMessageModalShown?: boolean;

  replyingMessage: {
    fromChatId?: string;
    messageId?: number;
    quoteText?: ApiFormattedText;
    quoteOffset?: number;
    toChatId?: string;
    toThreadId?: ThreadId;
  };

  forwardMessages: {
    fromChatId?: string;
    messageIds?: number[];
    storyId?: number;
    toChatId?: string;
    toThreadId?: ThreadId;
    withMyScore?: boolean;
    noAuthors?: boolean;
    noCaptions?: boolean;
  };

  pollResults: {
    chatId?: string;
    messageId?: number;
    votesByOption?: Record<string, PollVote[]>;
    offsets?: Record<string, string>;
  };

  isPaymentFormLoading?: boolean;
  payment: {
    inputInvoice?: ApiInputInvoice;
    step?: PaymentStep;
    status?: ApiPaymentStatus;
    shippingOptions?: ShippingOption[];
    requestId?: string;
    form?: ApiPaymentFormRegular;
    stripeCredentials?: {
      type: string;
      id: string;
    };
    smartGlocalCredentials?: {
      type: string;
      token: string;
    };
    receipt?: ApiReceiptRegular;
    error?: {
      field?: string;
      messageKey?: RegularLangFnParameters;
      descriptionKey?: RegularLangFnParameters;
    };
    isPaymentModalOpen?: boolean;
    isExtendedMedia?: boolean;
    confirmPaymentUrl?: string;
    temporaryPassword?: {
      value: string;
      validUntil: number;
    };
    url?: string;
    botId?: string;
  };
  starsPayment: {
    form?: ApiPaymentFormStars;
    subscriptionInfo?: ApiChatInviteInfo;
    inputInvoice?: ApiInputInvoice;
    status?: ApiPaymentStatus;
  };

  priceConfirmModal?: {
    originalAmount?: number;
    newAmount?: number;
    currency: 'TON' | 'XTR';
    directInfo?: {
      formId: string;
      inputInvoice: ApiInputInvoice;
    };
  };

  chatCreation?: {
    progress: ChatCreationProgress;
    error?: string;
  };

  profileEdit?: {
    progress: ProfileEditProgress;
    checkedUsername?: string;
    isUsernameAvailable?: boolean;
    error?: string;
  };

  notifications: ApiNotification[];
  dialogs: ApiDialog[];

  safeLinkModalUrl?: string;
  mapModal?: {
    point: ApiGeoPoint;
    zoom?: number;
  };
  historyCalendarSelectedAt?: number;
  openedStickerSetShortName?: string;
  openedCustomEmojiSetIds?: string[];

  reportAdModal?: {
    chatId?: string;
    randomId: string;
    sections: {
      title: string;
      subtitle?: string;
      options: {
        text: string;
        option: string;
      }[];
    }[];
  };

  reportModal?: {
    chatId?: string;
    messageIds: number[];
    description: string;
    peerId?: string;
    subject: 'story' | 'message';
    sections: {
      title?: string;
      subtitle?: string;
      options?: {
        text: string;
        option: string;
      }[];
      isOptional?: boolean;
      option?: string;
    }[];
  };

  activeDownloads: ActiveDownloads;

  statistics: {
    byChatId: Record<string, ApiChannelStatistics | ApiGroupStatistics>;
    currentMessage?: ApiPostStatistics;
    currentMessageId?: number;
    currentStory?: ApiPostStatistics;
    currentStoryId?: number;
    monetization?: ApiChannelMonetizationStatistics;
  };

  newContact?: {
    userId?: string;
    isByPhoneNumber?: boolean;
  };

  openedGame?: {
    url: string;
    chatId: string;
    messageId: number;
  };

  requestedDraft?: {
    chatId?: string;
    text: ApiFormattedText;
    files?: File[];
    filter?: ApiChatType[];
  };

  pollModal?: {
    chatId: string;
    threadId?: ThreadId;
    messageListType: MessageListType;
    isQuiz?: boolean;
  };

  todoListModal?: {
    chatId: string;
    messageId?: number;
    forNewTask?: boolean;
  };

  preparedMessageModal?: {
    message: ApiPreparedInlineMessage;
    webAppKey: string;
    botId: string;
  };

  sharePreparedMessageModal?: {
    webAppKey: string;
    message: ApiPreparedInlineMessage;
    filter: ApiChatType[];
    pendingSendArgs?: {
      peerId: string;
      threadId?: ThreadId;
      starsForSendMessage?: number;
    };
  };

  webApps: {
    activeWebAppKey?: string;
    openedOrderedKeys: string[];
    sessionKeys: string[];
    openedWebApps: Record<string, WebApp>;
    modalState: WebAppModalStateType;
    isModalOpen: boolean;
    isMoreAppsTabActive: boolean;
  };

  botTrustRequest?: {
    botId: string;
    type: 'game' | 'webApp' | 'botApp';
    shouldRequestWriteAccess?: boolean;
    onConfirm?: CallbackAction;
  };
  requestedAttachBotInstall?: {
    bot: ApiAttachBot;
    onConfirm?: CallbackAction;
  };
  requestedAttachBotInChat?: {
    bot: ApiAttachBot;
    filter: ApiChatType[];
    startParam?: string;
  };

  emojiStatusAccessModal?: {
    bot: ApiUser;
    webAppKey: string;
  };

  locationAccessModal?: {
    bot: ApiUser;
    webAppKey: string;
  };

  confetti?: {
    lastConfettiTime?: number;
    top?: number;
    left?: number;
    width?: number;
    height?: number;
    style?: ConfettiStyle;
    withStars?: boolean;
  };
  wave?: {
    lastWaveTime: number;
    startX: number;
    startY: number;
  };

  urlAuth?: {
    button?: {
      chatId: string;
      messageId: number;
      buttonId: number;
    };
    matchCode?: string;
    request?: Omit<ApiUrlAuthResultRequest, 'type' | 'bot'> & { botId: string };
    url: string;
  };

  premiumModal?: {
    isOpen?: boolean;
    promo: ApiPremiumPromo;
    initialSection?: ApiPremiumSection;
    fromUserId?: string;
    toUserId?: string;
    isGift?: boolean;
    daysAmount?: number;
    isSuccess?: boolean;
    gift?: ApiStarGift;
  };

  aiMessageEditorModal?: {
    chatId: string;
    text: ApiFormattedText;
    activeTab: 'translate' | 'style' | 'fix';
    isFromAttachment?: boolean;
    translateTab?: AiEditorTabBase & {
      selectedLanguage?: string;
      selectedTone?: ApiInputAiComposeTone;
      shouldEmojify?: boolean;
      cache?: Record<string, ApiComposedMessageWithAI>;
    };
    styleTab?: AiEditorTabBase & {
      selectedTone?: ApiInputAiComposeTone;
      shouldEmojify?: boolean;
      cache?: Record<string, ApiComposedMessageWithAI>;
    };
    fixTab?: AiEditorTabBase & {
      cache?: ApiComposedMessageWithAI;
    };
  };

  aiToneEditorModal?: {
    toneToEdit?: ApiAiComposeTone;
  };

  aiTonePreviewModal?: {
    slug: string;
    tone?: ApiAiComposeTone;
    example?: ApiAiComposeToneExample;
    isAlreadyAdded?: boolean;
    hasExampleError?: boolean;
  };

  aiMessageEditorPendingResult?: {
    text?: ApiFormattedText;
    shouldClear?: boolean;
    shouldSendWithAttachments?: boolean;
    isSilent?: boolean;
    scheduledAt?: number;
    scheduleRepeatPeriod?: number;
  };

  giveawayModal?: {
    chatId: string;
    isOpen?: boolean;
    gifts?: ApiPremiumGiftCodeOption[];
    selectedMemberIds?: string[];
    selectedChannelIds?: string[];
    prepaidGiveaway?: ApiTypePrepaidGiveaway;
    starOptions?: ApiStarGiveawayOption[];
  };

  deleteMessageModal?: {
    chatId: string;
    messageIds: number[];
    isSchedule?: boolean;
    onConfirm?: NoneToVoidFunction;
  };

  isWebAppsCloseConfirmationModalOpen?: boolean;

  isGiftRecipientPickerOpen?: boolean;

  isQuickChatPickerOpen?: boolean;

  isFrozenAccountModalOpen?: boolean;

  starsGiftingPickerModal?: {
    isOpen?: boolean;
  };

  starsGiftModal?: {
    isCompleted?: boolean;
    isOpen?: boolean;
    forUserId?: string;
    starsGiftOptions?: ApiStarTopupOption[];
  };

  starsTransactionModal?: {
    transaction: ApiStarsTransaction;
  };
  starsSubscriptionModal?: {
    subscription: ApiStarsSubscription;
  };

  giftModal?: {
    forPeerId: string;
    gifts?: ApiPremiumGiftCodeOption[];
    selectedResaleGift?: ApiStarGift;
    selectedGift?: ApiPremiumGiftCodeOption | ApiStarGift;
  };
  chatRefundModal?: {
    userId: string;
    starsToRefund: number;
  };

  disableSharingAboutModal?: {
    userId: string;
  };

  limitReachedModal?: {
    limit: ApiLimitTypeWithModal;
  };

  deleteFolderDialogModal?: number;

  createTopicPanel?: {
    chatId: string;
    isLoading?: boolean;
  };

  editTopicPanel?: {
    chatId: string;
    topicId: number;
    isLoading?: boolean;
  };

  requestedTranslations: {
    byChatId: Record<string, ChatRequestedTranslations>;
  };
  chatLanguageModal?: {
    chatId: string;
    messageId?: number;
    activeLanguage?: string;
  };

  chatlistModal?: {
    invite?: ApiChatlistInvite;
    removal?: {
      folderId: number;
      suggestedPeerIds?: string[];
    };
  };

  boostModal?: {
    chatId: string;
    boostStatus?: ApiBoostsStatus;
    myBoosts?: ApiMyBoost[];
  };

  boostStatistics?: {
    chatId: string;
    boostStatus?: ApiBoostsStatus;
    isLoadingBoosters?: boolean;
    nextOffset?: string;
    boosts?: {
      count: number;
      list: ApiBoost[];
    };
    giftedBoosts?: {
      count: number;
      list: ApiBoost[];
    };
  };

  monetizationStatistics?: {
    chatId: string;
  };

  giftCodeModal?: {
    slug: string;
    message?: {
      chatId: string;
      messageId: number;
    };
    info: ApiCheckedGiftCode;
  };

  deleteAccountModal?: {
    selfDestructAccountDays: number;
  };

  isAgeVerificationModalOpen?: boolean;

  birthdaySetupModal?: {
    currentBirthday?: ApiBirthday;
  };

  paidReactionModal?: {
    chatId: string;
    messageId: number;
  };

  suggestMessageModal?: {
    chatId: string;
    messageId?: number;
  };

  suggestedPostApprovalModal?: {
    chatId: string;
    messageId: number;
  };

  inviteViaLinkModal?: {
    missingUsers: ApiMissingInvitedUser[];
    chatId: string;
  };

  oneTimeMediaModal?: {
    message: ApiMessage;
  };

  collectibleInfoModal?: ApiCollectibleInfo & {
    peerId: string;
    type: 'phone' | 'username';
    collectible: string;
  };

  starsBalanceModal?: {
    originStarsPayment?: TabState['starsPayment'];
    originGift?: StarGiftInfo;
    originReaction?: {
      chatId: string;
      messageId: number;
      amount: number;
    };
    topup?: {
      balanceNeeded: number;
      purpose?: string;
    };
    currency?: ApiTypeCurrencyAmount['currency'];
  };

  giftInfoModal?: {
    peerId?: string;
    recipientId?: string;
    gift: ApiSavedStarGift | ApiStarGift;
    craftSlotIndex?: number;
  };

  giftInfoValueModal?: {
    valueInfo: ApiUniqueStarGiftValueInfo;
    gift: ApiStarGiftUnique;
  };

  lockedGiftModal?: {
    untilDate?: number;
    reason?: ApiFormattedText;
  };

  giftResalePriceComposerModal?: {
    peerId?: string;
    gift: ApiSavedStarGift | ApiStarGift;
  };

  giftTransferModal?: {
    gift: ApiSavedStarGift;
  };

  giftTransferConfirmModal?: {
    gift: ApiSavedStarGift;
    recipientId: string;
  };

  giftDescriptionRemoveModal?: {
    gift: ApiSavedStarGift;
    price: number;
    details: ApiStarGiftAttributeOriginalDetails;
  };

  giftOfferAcceptModal?: {
    peerId: string;
    messageId: number;
    gift: ApiStarGiftUnique;
    price: ApiTypeCurrencyAmount;
  };

  giftUpgradeModal?: {
    sampleAttributes: ApiStarGiftAttribute[];
    recipientId?: string;
    gift?: ApiSavedStarGift;
    prices?: ApiStarGiftUpgradePrice[];
    nextPrices?: ApiStarGiftUpgradePrice[];
    currentUpgradeStars?: number;
    minPrice?: number;
    maxPrice?: number;
  };

  giftCraftModal?: {
    regularGiftId?: string;
    regularGiftTitle?: string;
    gift1?: ApiSavedStarGift;
    gift2?: ApiSavedStarGift;
    gift3?: ApiSavedStarGift;
    gift4?: ApiSavedStarGift;
    previewAttributes?: ApiStarGiftAttribute[];
    myCraftableGifts?: ApiSavedStarGift[];
    myCraftableGiftsNextOffset?: string;
    shouldRefreshMyCraftableGifts?: boolean;
    marketCraftableGifts?: ApiStarGiftUnique[];
    marketCraftableGiftsNextOffset?: string;
    marketCraftableGiftsCount?: number;
    isMarketLoading?: boolean;
    marketFilter: ResaleGiftsFilterOptions;
    marketAttributes?: ApiStarGiftAttribute[];
    marketCounters?: ApiStarGiftAttributeCounter[];
    marketAttributesHash?: string;
    marketUpdateIteration: number;
    craftResult?: {
      success: true;
      gift: ApiStarGiftUnique;
    } | {
      success: false;
      isError?: true;
    };
  };

  giftCraftSelectModal?: {
    slotIndex: number;
    isLoading?: boolean;
  };

  giftCraftInfoModal?: {
    gift: ApiStarGiftUnique;
  };

  giftWithdrawModal?: {
    gift: ApiSavedStarGift;
    isLoading?: boolean;
    errorKey?: RegularLangFnParameters;
  };

  giftStatusInfoModal?: {
    emojiStatus: ApiEmojiStatusCollectible;
  };

  giftPreviewModal?: {
    attributes: ApiStarGiftAttribute[];
    originGift: ApiStarGift;
    shouldShowCraftableOnStart?: boolean;
  };

  giftAuctionModal?: {
    auctionGiftId: string;
    sampleAttributes?: ApiStarGiftAttribute[];
  };

  giftAuctionBidModal?: {
    auctionGiftId: string;
    peerId?: string;
    message?: string;
    shouldHideName?: boolean;
  };

  giftAuctionInfoModal?: {
    auctionGiftId: string;
  };

  aboutStarGiftModal?: {
    videoId?: string;
    videoThumbnail?: ApiThumbnail;
  };

  giftAuctionChangeRecipientModal?: {
    auctionGiftId: string;
    oldPeerId?: string;
    newPeerId?: string;
    message?: string;
    shouldHideName?: boolean;
  };

  giftAuctionAcquiredModal?: {
    giftId?: string;
    giftTitle?: string;
    giftSticker?: ApiSticker;
    acquiredGifts?: ApiStarGiftAuctionAcquiredGift[];
  };

  activeGiftAuctionsModal?: true;

  starGiftPriceDecreaseInfoModal?: {
    prices: ApiStarGiftUpgradePrice[];
    currentPrice: number;
    minPrice: number;
    maxPrice: number;
  };

  suggestedStatusModal?: {
    botId: string;
    webAppKey?: string;
    customEmojiId: string;
    duration?: number;
  };

  profileRatingModal?: {
    userId: string;
    level: number;
  };

  monetizationVerificationModal?: {
    chatId: string;
    isLoading?: boolean;
    errorKey?: RegularLangFnParameters;
  };

  quickPreview?: {
    chatId: string;
    threadId?: ThreadId;
  };

  isPasskeyModalOpen?: boolean;

  leaveGroupModal?: {
    chatId: string;
    nextOwnerId?: string;
  };

  isTwoFaCheckModalOpen?: true;

  isWaitingForStarGiftUpgrade?: true;
  isWaitingForStarGiftTransfer?: true;
  insertingPeerIdMention?: string;
  shouldSaveAttachmentsCompression?: boolean;

  isCocoonModalOpen?: boolean;

  rankModal?: {
    chatId: string;
    userId: string;
    isAdmin?: boolean;
    isOwner?: boolean;
    rank?: string;
  };
  editRankModal?: {
    chatId: string;
    userId: string;
    isAdmin?: boolean;
    isOwner?: boolean;
    rank?: string;
  };
  shouldOpenMessageMediaEditor?: boolean;
};
