syntax = "proto3";

package signal;

import "ResumableUploads.proto";

option java_package        = "org.thoughtcrime.securesms.jobs.protos";
option java_multiple_files = true;

import SignalService.proto;

message CallSyncEventJobRecord {

  enum Event {
    UNKNOWN_ACTION = 0;
    ACCEPTED       = 1;
    NOT_ACCEPTED   = 2;
    DELETE         = 3;
    OBSERVED       = 4;
  }

  uint64 recipientId     = 1;
  reserved                 2;
  uint64 callId          = 3;
  uint32 direction       = 4;
  uint32 deprecatedEvent = 5; // Deprecated for callEvent.
  Event  callEvent       = 6;
}

message CallSyncEventJobData {
  repeated CallSyncEventJobRecord records = 1;
}

message CallLinkRefreshSinceTimestampJobData {
  uint64 timestamp = 1;
}

message CallLogEventSendJobData {
  bytes callLogEvent = 1;
}

message CallLinkUpdateSendJobData {
  enum Type {
    UPDATE = 0;
    reserved 1; // was DELETE, superseded by storage service
  }

  string        callLinkRoomId = 1;
  optional Type type           = 2;
}

message AttachmentUploadJobData {
  uint64 attachmentId = 1;
  reserved /*attachmentUniqueId*/ 2;
  optional ResumableUpload uploadSpec = 3;
}

message PreKeysSyncJobData {
  bool forceRefreshRequested = 1;
}

message ArchiveThumbnailUploadJobData {
  uint64 attachmentId = 1;
}

message InAppPaymentRedemptionJobData {
  oneof id {
    uint64 inAppPaymentId = 1;
    uint64 giftMessageId  = 2;
  }

  bool makePrimary = 3;
  bool isFromAuthCheck = 4;
}

message DeleteSyncJobData {
  message AddressableMessage {
    uint64 threadRecipientId = 1;
    uint64 sentTimestamp = 2;
    uint64 authorRecipientId = 3;
  }

  message AttachmentDelete {
    AddressableMessage targetMessage = 1;
    optional bytes uuid = 2;
    optional bytes digest = 3;
    optional bytes plaintextHash = 4;
  }

  message ThreadDelete {
    uint64 threadRecipientId = 1;
    repeated AddressableMessage messages = 2;
    bool isFullDelete = 3;
    repeated AddressableMessage nonExpiringMessages = 4;
  }

  repeated AddressableMessage messageDeletes = 1;
  repeated ThreadDelete threadDeletes = 2;
  repeated ThreadDelete localOnlyThreadDeletes = 3;
  repeated AttachmentDelete attachmentDeletes = 4;
}

message Svr3MirrorJobData {
  optional string serializedChangeSession = 1;
}

message GroupCallPeekJobData {
  uint64 groupRecipientId  = 1;
  uint64 senderRecipientId = 2;
  uint64 serverTimestamp   = 3;
}

message RestoreLocalAttachmentJobData {
  uint64 attachmentId = 1;
  uint64 messageId = 2;
  string fileUri = 3;
  uint64 fileSize = 4;
}

message BackfillDigestJobData {
  uint64 attachmentId = 1;
}

message BackfillDigestsForDataFileJobData {
  string dataFile = 1;
}

message RestoreAttachmentJobData {
  uint64 messageId = 1;
  uint64 attachmentId = 2;
  bool manual = 3;
}

message CopyAttachmentToArchiveJobData {
  uint64 attachmentId = 1;
}

message UploadAttachmentToArchiveJobData {
  uint64 attachmentId = 1;
  ResumableUpload uploadSpec = 2;
  optional bool canReuseUpload = 3;
}

message ArchiveAttachmentReconciliationJobData {
  optional uint64 snapshot = 1;
  string serverCursor = 2;
  bool forced = 3;
}

message DeviceNameChangeJobData {
  uint32 deviceId = 1;
}

message BackupMessagesJobData {
  uint64 syncTime = 1;
  string dataFile = 2;
  ResumableUpload uploadSpec = 3;
  string resumableUri = 4;
}

message NewLinkedDeviceNotificationJobData {
  uint32 deviceId = 1;
  uint64 deviceCreatedAt = 2;
}

message MultiDeviceAttachmentBackfillMissingJobData {
  signalservice.AddressableMessage targetMessage = 1;
  signalservice.ConversationIdentifier targetConversation = 2;
}

message MultiDeviceAttachmentBackfillUpdateJobData {
  signalservice.AddressableMessage targetMessage = 1;
  signalservice.ConversationIdentifier targetConversation = 2;
  uint64 messageId = 3;
}

message InAppPaymentSourceData {
  enum Code {
    UNKNOWN = 0;
    PAY_PAL = 1;
    CREDIT_CARD = 2;
    GOOGLE_PAY = 3;
    SEPA_DEBIT = 4;
    IDEAL = 5;
    GOOGLE_PLAY_BILLING = 6;
  }

  message TokenData {
    string parameters = 1;
    string tokenId = 2;
    optional string email = 3;
  }

  message IDEALData {
    reserved 1; // bank, no longer utilized.
    string name = 2;
    string email = 3;
  }

  message SEPAData {
    string iban = 1;
    string name = 2;
    string email = 3;
  }

  Code code = 1;

  oneof data {
    TokenData tokenData = 2;
    IDEALData idealData = 3;
    SEPAData sepaData = 4;
  }
}

message InAppPaymentSetupJobData {
  uint64 inAppPaymentId = 1;
  InAppPaymentSourceData inAppPaymentSource = 2;
}

message StorageSyncJobData {
  bool localManifestOutOfDate = 1;
}

message BackupDeleteJobData {
  enum Stage {
    UNKNOWN = 0;
    CANCEL_SUBSCRIBER = 1;
    DELETE_MESSAGES = 2;
    DELETE_MEDIA = 3;
    CLEAR_LOCAL_STATE = 4;
  }

  enum Tier {
    UNKNOWN_TIER = 0;
    FREE = 1;
    PAID = 2;
  }

  repeated Stage completed = 1;
  Tier tier = 2;
}

message SecondRoundFixupSendJobData {
  uint64 messageId = 1;
}

message PollVoteJobData {
  uint64 messageId = 1;
  repeated uint64 recipients = 2;
  uint32 initialRecipientCount = 3;
  uint32 voteCount = 4;
  bool isRemoval = 5;
  uint64 optionId = 6;
}