syntax = "proto3";

option java_package = "com.audible.playersdk.downloadqueue.datamodel";
option java_multiple_files = true;


/**
 * SessionInfo is session related info in current DownloadRequest data object.
 * @see [com.audible.playersdk.download.downloader.model.downloadrequest.DownloadRequest]
 */
message SessionInfo {
  optional string playback_session_id = 1;
  optional string download_session_id = 2;
}

/**
 *  SupportedFormats is from GlobalLibrary item's audio formats during generating download request.
 *  Stored it in datastore because it is still used by current downloadItem.
 *  @see [com.audible.playersdk.download.downloader.model.downloadrequest.DownloadRequest]
 */
message SupportedFormats {
  repeated string format = 1;
}

/**
 * Download Queue item's enqueue status.
 * Download task only could be handled after enqueuing is successful.
 */
enum EnqueueStatus {
  Waiting = 0; // in the preProcess
  Canceling = 1; // in the preProcess, but will remove from downloadQueue
  // Queueing = 2; // queue processor is working in queueing the item
  Retry = 3; //  failed on enqueue, retry
  Success = 4; //  success on enqueue
  // Failed = 5; // failed on enqueue, ideally, this status wont be used in QueueItem, as failed QueueItem wont be put in any Queue
}

/**
 * Download task's status.
 * It's used for reflecting each enqueued download tasks' download status.
 */
enum DownloadQueueStatus {
  Pending = 0;
  Connecting = 1;
  Downloading = 2;
  Paused = 3;
  Done = 4;
  Error = 5;
  Updating = 6;
}

/**
 * DownloadQueueRequest is mapped to DownloadRequest which is used in current app.
 * @see [com.audible.playersdk.download.downloader.model.downloadrequest.DownloadRequest]
 */
message DownloadQueueRequest {
    string asin = 1;
    string product_id = 2;
    SessionInfo sessionInfo = 3;
    string parent_asin = 4;
    string sku_lite = 5;
    string title = 6;
    // string preferredFormat = 7; // we will use download_quality to stands for user preferred download quality
    bool skip_remote_lph = 8;
    bool suppress_user_messages = 9;
    bool from_auto_download = 10;
    bool start_immediately = 11;
    string acr = 12;
    bool allow_license_event = 13;
    int32 preferred_download_format = 14;
    int64 enqueue_timestamp = 15;
    SupportedFormats supportedFormats = 16;
    int32 download_quality = 17;
    optional string ebook_asin = 18;
    optional string ebook_acr = 19;
}

/**
 * DownloadQueueItemMetadata is mapped to DownloadItemMetadata which is used in current downloadItem.
 */
message DownloadQueueItemMetadata {
  string audio_codec = 1;
  string download_url = 2;
  string drm = 3;
  string content_format = 4;
  int64  content_size_in_bytes = 5;
  string acr = 6;
  string pdf_url = 7;
  string version = 8;
  int32 duration = 9;
  AudioFeatures audio_features = 11;
  optional DownloadQueueSupplementalAssetsMetadata supplemental_assets_metadata = 12;
  repeated DownloadQueueChapters chapters = 13;
}

message DownloadQueueChapters {
  int64 chapterLevel = 1;
  int64 length = 2;
  int64 startPosition = 3;
  string title = 4;
  repeated DownloadQueueChapters chapters = 5;
}

message DownloadQueueSupplementalAssetsMetadata {
  string ebook_asin = 1;
  string ebook_acr = 2;
  string ebook_version = 3;
  optional string sync_file_acr = 4;
  optional string sync_file_url = 5;
}

/**
 * AudioFeature Info in DownloadMetadata
 */
message AudioFeatures {
  repeated string feature = 1;
}

/**
 * DownloadItemProgress contains metadata which is needed for UI updates.
 * It may be only useful for current downloading item.
 */
message DownloadItemProgress {
  int32 status = 1;
  int64 bytes_downloaded = 2;
  int64 total_bytes_to_download = 3;
  int64 title_size = 4;
  int64 initial_byte_offset = 5;
  bool can_play_title = 6;
  int32 progress_percentage = 7;
}

/**
 * DownloadQueueItem contains all information what current DownloadItem has.
 */
message DownloadQueueItem {
  DownloadQueueRequest download_request = 1;
  optional DownloadQueueItemMetadata download_metadata = 2;
  optional DownloadItemProgress cached_progress = 3;
  EnqueueStatus queue_status = 4;
  DownloadQueueStatus download_status = 5;
}

/**
 * Queue to store downloadQueueItems.
 */
message DownloadQueue {
  repeated DownloadQueueItem items  = 1;
}