import * as api from '@airgram/api'
import { Airgram } from 'tdweb-airgram'
import Vue, { VueConstructor } from 'vue'
import { DollarTd } from './DollarTd'
import { TdProvider } from './TdProvider'

export interface BaseTdHandlers {
  updateAuthorizationState?: (update: api.UpdateAuthorizationState, context: TdEventContext) => any
  updateNewMessage?: (update: api.UpdateNewMessage, context: TdEventContext) => any
  updateMessageSendAcknowledged?: (update: api.UpdateMessageSendAcknowledged, context: TdEventContext) => any
  updateMessageSendSucceeded?: (update: api.UpdateMessageSendSucceeded, context: TdEventContext) => any
  updateMessageSendFailed?: (update: api.UpdateMessageSendFailed, context: TdEventContext) => any
  updateMessageContent?: (update: api.UpdateMessageContent, context: TdEventContext) => any
  updateMessageEdited?: (update: api.UpdateMessageEdited, context: TdEventContext) => any
  updateMessageViews?: (update: api.UpdateMessageViews, context: TdEventContext) => any
  updateMessageContentOpened?: (update: api.UpdateMessageContentOpened, context: TdEventContext) => any
  updateMessageMentionRead?: (update: api.UpdateMessageMentionRead, context: TdEventContext) => any
  updateNewChat?: (update: api.UpdateNewChat, context: TdEventContext) => any
  updateChatTitle?: (update: api.UpdateChatTitle, context: TdEventContext) => any
  updateChatPhoto?: (update: api.UpdateChatPhoto, context: TdEventContext) => any
  updateChatLastMessage?: (update: api.UpdateChatLastMessage, context: TdEventContext) => any
  updateChatOrder?: (update: api.UpdateChatOrder, context: TdEventContext) => any
  updateChatIsPinned?: (update: api.UpdateChatIsPinned, context: TdEventContext) => any
  updateChatIsMarkedAsUnread?: (update: api.UpdateChatIsMarkedAsUnread, context: TdEventContext) => any
  updateChatIsSponsored?: (update: api.UpdateChatIsSponsored, context: TdEventContext) => any
  updateChatDefaultDisableNotification?: (
    update: api.UpdateChatDefaultDisableNotification, context: TdEventContext) => any
  updateChatReadInbox?: (update: api.UpdateChatReadInbox, context: TdEventContext) => any
  updateChatReadOutbox?: (update: api.UpdateChatReadOutbox, context: TdEventContext) => any
  updateChatUnreadMentionCount?: (update: api.UpdateChatUnreadMentionCount, context: TdEventContext) => any
  updateChatNotificationSettings?: (update: api.UpdateChatNotificationSettings, context: TdEventContext) => any
  updateScopeNotificationSettings?: (update: api.UpdateScopeNotificationSettings, context: TdEventContext) => any
  updateChatPinnedMessage?: (update: api.UpdateChatPinnedMessage, context: TdEventContext) => any
  updateChatReplyMarkup?: (update: api.UpdateChatReplyMarkup, context: TdEventContext) => any
  updateChatDraftMessage?: (update: api.UpdateChatDraftMessage, context: TdEventContext) => any
  updateChatOnlineMemberCount?: (update: api.UpdateChatOnlineMemberCount, context: TdEventContext) => any
  updateNotification?: (update: api.UpdateNotification, context: TdEventContext) => any
  updateNotificationGroup?: (update: api.UpdateNotificationGroup, context: TdEventContext) => any
  updateActiveNotifications?: (update: api.UpdateActiveNotifications, context: TdEventContext) => any
  updateHavePendingNotifications?: (update: api.UpdateHavePendingNotifications, context: TdEventContext) => any
  updateDeleteMessages?: (update: api.UpdateDeleteMessages, context: TdEventContext) => any
  updateUserChatAction?: (update: api.UpdateUserChatAction, context: TdEventContext) => any
  updateUserStatus?: (update: api.UpdateUserStatus, context: TdEventContext) => any
  updateUser?: (update: api.UpdateUser, context: TdEventContext) => any
  updateBasicGroup?: (update: api.UpdateBasicGroup, context: TdEventContext) => any
  updateSupergroup?: (update: api.UpdateSupergroup, context: TdEventContext) => any
  updateSecretChat?: (update: api.UpdateSecretChat, context: TdEventContext) => any
  updateUserFullInfo?: (update: api.UpdateUserFullInfo, context: TdEventContext) => any
  updateBasicGroupFullInfo?: (update: api.UpdateBasicGroupFullInfo, context: TdEventContext) => any
  updateSupergroupFullInfo?: (update: api.UpdateSupergroupFullInfo, context: TdEventContext) => any
  updateServiceNotification?: (update: api.UpdateServiceNotification, context: TdEventContext) => any
  updateFile?: (update: api.UpdateFile, context: TdEventContext) => any
  updateFileGenerationStart?: (update: api.UpdateFileGenerationStart, context: TdEventContext) => any
  updateFileGenerationStop?: (update: api.UpdateFileGenerationStop, context: TdEventContext) => any
  updateCall?: (update: api.UpdateCall, context: TdEventContext) => any
  updateUserPrivacySettingRules?: (update: api.UpdateUserPrivacySettingRules, context: TdEventContext) => any
  updateUnreadMessageCount?: (update: api.UpdateUnreadMessageCount, context: TdEventContext) => any
  updateUnreadChatCount?: (update: api.UpdateUnreadChatCount, context: TdEventContext) => any
  updateOption?: (update: api.UpdateOption, context: TdEventContext) => any
  updateInstalledStickerSets?: (update: api.UpdateInstalledStickerSets, context: TdEventContext) => any
  updateTrendingStickerSets?: (update: api.UpdateTrendingStickerSets, context: TdEventContext) => any
  updateRecentStickers?: (update: api.UpdateRecentStickers, context: TdEventContext) => any
  updateFavoriteStickers?: (update: api.UpdateFavoriteStickers, context: TdEventContext) => any
  updateSavedAnimations?: (update: api.UpdateSavedAnimations, context: TdEventContext) => any
  updateLanguagePackStrings?: (update: api.UpdateLanguagePackStrings, context: TdEventContext) => any
  updateConnectionState?: (update: api.UpdateConnectionState, context: TdEventContext) => any
  updateTermsOfService?: (update: api.UpdateTermsOfService, context: TdEventContext) => any
  updateNewInlineQuery?: (update: api.UpdateNewInlineQuery, context: TdEventContext) => any
  updateNewChosenInlineResult?: (update: api.UpdateNewChosenInlineResult, context: TdEventContext) => any
  updateNewCallbackQuery?: (update: api.UpdateNewCallbackQuery, context: TdEventContext) => any
  updateNewInlineCallbackQuery?: (update: api.UpdateNewInlineCallbackQuery, context: TdEventContext) => any
  updateNewShippingQuery?: (update: api.UpdateNewShippingQuery, context: TdEventContext) => any
  updateNewPreCheckoutQuery?: (update: api.UpdateNewPreCheckoutQuery, context: TdEventContext) => any
  updateNewCustomEvent?: (update: api.UpdateNewCustomEvent, context: TdEventContext) => any
  updateNewCustomQuery?: (update: api.UpdateNewCustomQuery, context: TdEventContext) => any
  updatePoll?: (update: api.UpdatePoll, context: TdEventContext) => any
}

export type TdHandler = (update: any, context: TdEventContext) => any

export type TdHandlers = BaseTdHandlers & Record<string, TdHandler>

export interface TdVue extends Vue {
  $_tdSubscriptions?: Array<() => void>
  $_tdProvider: TdProvider
  $_td?: DollarTd
}

export interface TdVueConstructor extends VueConstructor, TdVue {}

export interface TdEventContext extends Airgram.ContextState {
  airgram: Airgram.AirgramInstance
}

export type TdEventHandler = (update: any, context: TdEventContext) => any
