syntax = "proto3";

package apprelease;

service AppReleaseService {
  rpc ListAppReleases (ListAppReleasesRequest) returns (ListAppReleasesResponse);
  rpc ListPublicAppReleases (ListPublicAppReleasesRequest) returns (ListAppReleasesResponse);
  rpc CreateAppRelease (CreateAppReleaseRequest) returns (AppRelease);
  rpc UpdateAppRelease (UpdateAppReleaseRequest) returns (AppRelease);
  rpc DeleteAppRelease (DeleteAppReleaseRequest) returns (Empty);
  rpc GetLatestAppRelease (GetLatestAppReleaseRequest) returns (AppRelease);
  rpc CheckAppUpdate (CheckAppUpdateRequest) returns (CheckAppUpdateResponse);
  rpc ResolveAppReleaseDownload (ResolveAppReleaseDownloadRequest) returns (AppReleaseDownloadResponse);
}

message Empty {}

message AppRelease {
  string id = 1;
  string platform = 2;
  string version = 3;
  int32 versionCode = 4;
  string fileName = 5;
  string storageKey = 6;
  string fileSize = 7;
  string sha256 = 8;
  optional string releaseNotes = 9;
  bool isPublished = 10;
  string createdAt = 11;
  string updatedAt = 12;
}

message ListAppReleasesRequest {
  optional string platform = 1;
}

message ListPublicAppReleasesRequest {
  optional string platform = 1;
}

message ListAppReleasesResponse {
  repeated AppRelease releases = 1;
}

message CreateAppReleaseRequest {
  string platform = 1;
  string version = 2;
  int32 versionCode = 3;
  string fileName = 4;
  string storageKey = 5;
  string fileSize = 6;
  string sha256 = 7;
  optional string releaseNotes = 8;
  optional string createdById = 9;
}

message UpdateAppReleaseRequest {
  string releaseId = 1;
  optional bool isPublished = 2;
  optional string releaseNotes = 3;
}

message DeleteAppReleaseRequest {
  string releaseId = 1;
}

message GetLatestAppReleaseRequest {
  string platform = 1;
}

message CheckAppUpdateRequest {
  string platform = 1;
  int32 versionCode = 2;
}

message CheckAppUpdateResponse {
  bool updateAvailable = 1;
  optional AppRelease latest = 2;
}

message ResolveAppReleaseDownloadRequest {
  string platform = 1;
  optional string releaseId = 2;
}

message AppReleaseDownloadResponse {
  string storageKey = 1;
  string fileName = 2;
  string contentType = 3;
  string fileSize = 4;
  string sha256 = 5;
  string version = 6;
  int32 versionCode = 7;
}
