syntax = "proto3";

package odl.download_metadata;

// what we want to do is to know how many parts initially were aiming for
// in case user increases the connection count compared to the initial settings,
// we need to increase the parts as well,
// but if user decreases the connection count, we need to keep the parts count the same
// we will just finish downloading each part and then concatenate them at the end

message DownloadMetadata {
  string url = 1;
  string filename = 2;
  string save_dir = 3;
  bool is_resumable = 4;
  bool use_server_time = 5;
  optional int64 last_modified = 6;
  optional string last_etag = 7;
  // final size reported by server
  optional uint64 size = 8;
  // file checksums provided by server
  repeated FileChecksum checksums = 9;
  bool requires_auth = 10;
  bool requires_basic_auth = 11;
  map<string, string> headers = 12;
  uint64 max_connections = 13;
  map<string, PartDetails> parts = 14; // ulid -> PartDetails
  bool finished = 15;
}

message PartDetails {
  uint64 offset = 1;
  uint64 size = 2;
  string ulid = 3; // file name = `ulid` + `'.part'`
  bool finished = 4; // important for failure detection (Unexpected crashes, power loss, etc.)
}

message FileChecksum {
  ChecksumAlgorithm algorithm = 1;
  string digest = 2;
  ChecksumEncoding encoding = 3;
}

enum ChecksumAlgorithm { 
  sha512 = 0;
  sha384 = 1; 
  sha256 = 2; 
  sha1 = 3; 
  md5 = 4; 
}

enum ChecksumEncoding {
  hex = 0;
  base64 = 1;
}
