syntax = "proto3";
package HistorySync;

import "../ChatLockSettings/ChatLockSettings.proto";
import "../E2E/E2E.proto";
import "../Web/Web.proto";
import "../Protocol/Protocol.proto";
import "../SyncAction/SyncAction.proto";

message NotificationSettings {
    optional string messageVibrate = 1;
    optional string messagePopup = 2;
    optional string messageLight = 3;
    optional bool lowPriorityNotifications = 4;
    optional bool reactionsMuted = 5;
    optional string callVibrate = 6;
}

message AvatarUserSettings {
    optional string fbid = 1;
    optional string password = 2;
}

message PastParticipant {
    optional string userJid = 1;
    optional LeaveReason leaveReason = 2;
    optional uint64 leaveTs = 3;
    enum LeaveReason {
        LEFT = 0;
        REMOVED = 1;
    }
}

message PastParticipants {
    optional string groupJid = 1;
    repeated PastParticipant pastParticipants = 2;
}

message StickerMetadata {
    optional string url = 1;
    optional bytes fileSha256 = 2;
    optional bytes fileEncSha256 = 3;
    optional bytes mediaKey = 4;
    optional string mimetype = 5;
    optional uint32 height = 6;
    optional uint32 width = 7;
    optional string directPath = 8;
    optional uint64 fileLength = 9;
    optional float weight = 10;
    optional int64 lastStickerSentTs = 11;
    optional bool isLottie = 12;
    optional string imageHash = 13;
    optional bool isAvatarSticker = 14;
}

message AutoDownloadSettings {
    optional bool downloadImages = 1;
    optional bool downloadAudio = 2;
    optional bool downloadVideo = 3;
    optional bool downloadDocuments = 4;
}

message GlobalSettings {
    optional WallpaperSettings lightThemeWallpaper = 1;
    optional MediaVisibility mediaVisibility = 2;
    optional WallpaperSettings darkThemeWallpaper = 3;
    optional AutoDownloadSettings autoDownloadWiFi = 4;
    optional AutoDownloadSettings autoDownloadCellular = 5;
    optional AutoDownloadSettings autoDownloadRoaming = 6;
    optional bool showIndividualNotificationsPreview = 7;
    optional bool showGroupNotificationsPreview = 8;
    optional int32 disappearingModeDuration = 9;
    optional int64 disappearingModeTimestamp = 10;
    optional AvatarUserSettings avatarUserSettings = 11;
    optional int32 fontSize = 12;
    optional bool securityNotifications = 13;
    optional bool autoUnarchiveChats = 14;
    optional int32 videoQualityMode = 15;
    optional int32 photoQualityMode = 16;
    optional NotificationSettings individualNotificationSettings = 17;
    optional NotificationSettings groupNotificationSettings = 18;
    optional ChatLockSettings.ChatLockSettings chatLockSettings = 19;
    optional int64 chatDbLidMigrationTimestamp = 20;
}

message WallpaperSettings {
    optional string filename = 1;
    optional uint32 opacity = 2;
}

message GroupParticipant {
    required string userJid = 1;
    optional Rank rank = 2;
    optional E2E.MemberLabel memberLabel = 3;
    enum Rank {
        REGULAR = 0;
        ADMIN = 1;
        SUPERADMIN = 2;
    }
}

message Pushname {
    optional string id = 1;
    optional string pushname = 2;
}

message HistorySyncMsg {
    optional Web.WebMessageInfo message = 1;
    optional uint64 msgOrderId = 2;
}

message Account {
    optional string lid = 1;
    optional string username = 2;
    optional string countryCode = 3;
    optional bool isUsernameDeleted = 4;
}

message PhoneNumberToLIDMapping {
    optional string pnJid = 1;
    optional string lidJid = 2;
}

message Conversation {
    required string id = 1;
    repeated HistorySyncMsg messages = 2;
    optional string newJid = 3;
    optional string oldJid = 4;
    optional uint64 lastMsgTimestamp = 5;
    optional uint32 unreadCount = 6;
    optional bool readOnly = 7;
    optional bool endOfHistoryTransfer = 8;
    optional uint32 ephemeralExpiration = 9;
    optional int64 ephemeralSettingTimestamp = 10;
    optional EndOfHistoryTransferType endOfHistoryTransferType = 11;
    optional uint64 conversationTimestamp = 12;
    optional string name = 13;
    optional string pHash = 14;
    optional bool notSpam = 15;
    optional bool archived = 16;
    optional E2E.DisappearingMode disappearingMode = 17;
    optional uint32 unreadMentionCount = 18;
    optional bool markedAsUnread = 19;
    repeated GroupParticipant participant = 20;
    optional bytes tcToken = 21;
    optional uint64 tcTokenTimestamp = 22;
    optional bytes contactPrimaryIdentityKey = 23;
    optional uint32 pinned = 24;
    optional uint64 muteEndTime = 25;
    optional WallpaperSettings wallpaper = 26;
    optional MediaVisibility mediaVisibility = 27;
    optional uint64 tcTokenSenderTimestamp = 28;
    optional bool suspended = 29;
    optional bool terminated = 30;
    optional uint64 createdAt = 31;
    optional string createdBy = 32;
    optional string description = 33;
    optional bool support = 34;
    optional bool isParentGroup = 35;
    optional string parentGroupId = 37;
    optional bool isDefaultSubgroup = 36;
    optional string displayName = 38;
    optional string pnJid = 39;
    optional bool shareOwnPn = 40;
    optional bool pnhDuplicateLidThread = 41;
    optional string lidJid = 42;
    optional string username = 43;
    optional string lidOriginType = 44;
    optional uint32 commentsCount = 45;
    optional bool locked = 46;
    optional PrivacySystemMessage systemMessageToInsert = 47;
    optional bool capiCreatedGroup = 48;
    optional string accountLid = 49;
    optional bool limitSharing = 50;
    optional int64 limitSharingSettingTimestamp = 51;
    optional Protocol.LimitSharing.TriggerType limitSharingTrigger = 52;
    optional bool limitSharingInitiatedByMe = 53;
    optional bool maibaAiThreadEnabled = 54;
    enum EndOfHistoryTransferType {
        COMPLETE_BUT_MORE_MESSAGES_REMAIN_ON_PRIMARY = 0;
        COMPLETE_AND_NO_MORE_MESSAGE_REMAIN_ON_PRIMARY = 1;
        COMPLETE_ON_DEMAND_SYNC_BUT_MORE_MSG_REMAIN_ON_PRIMARY = 2;
    }
}

message HistorySync {
    required HistorySyncType syncType = 1;
    repeated Conversation conversations = 2;
    repeated Web.WebMessageInfo statusV3Messages = 3;
    optional uint32 chunkOrder = 5;
    optional uint32 progress = 6;
    repeated Pushname pushnames = 7;
    optional GlobalSettings globalSettings = 8;
    optional bytes threadIdUserSecret = 9;
    optional uint32 threadDsTimeframeOffset = 10;
    repeated StickerMetadata recentStickers = 11;
    repeated PastParticipants pastParticipants = 12;
    repeated SyncAction.CallLogRecord callLogRecords = 13;
    optional BotAIWaitListState aiWaitListState = 14;
    repeated PhoneNumberToLIDMapping phoneNumberToLidMappings = 15;
    optional string companionMetaNonce = 16;
    optional bytes shareableChatIdentifierEncryptionKey = 17;
    repeated Account accounts = 18;
    enum BotAIWaitListState {
        IN_WAITLIST = 0;
        AI_AVAILABLE = 1;
    }
    enum HistorySyncType {
        INITIAL_BOOTSTRAP = 0;
        INITIAL_STATUS_V3 = 1;
        FULL = 2;
        RECENT = 3;
        PUSH_NAME = 4;
        NON_BLOCKING_DATA = 5;
        ON_DEMAND = 6;
    }
}

enum PrivacySystemMessage {
    E2EE_MSG = 1;
    NE2EE_SELF = 2;
    NE2EE_OTHER = 3;
}

enum MediaVisibility {
    DEFAULT = 0;
    OFF = 1;
    ON = 2;
}