syntax = "proto3";

package devvit.dev_portal.app_version;

import "devvit/dev_portal/actor/actor_type.proto";
import "devvit/dev_portal/app/info/app_info.proto";
import "devvit/dev_portal/app_version/info/app_version_info.proto";
import "devvit/dev_portal/installation/installation.proto";
import "devvit/plugin/buildpack/buildpack_common.proto";
import "devvit/runtime/bundle.proto";
import "google/protobuf/wrappers.proto";

option go_package = "github.snooguts.net/reddit/reddit-devplatform-monorepo/go-common/generated/protos/types/devvit/devportal/appversion";

// region Request parameters

// Used to create a new app version.
message AppVersionCreationRequest {
  // What is the ID of the app this version belongs to?
  string app_id = 1;

  // How visible is this app version?
  info.VersionVisibility visibility = 2;
  // What installation types are allowed for this app?
  repeated info.InstallationType valid_install_types = 3;
  // What is this version's major version number? i.e. x.0.0
  int32 major_version = 4;
  // What is this version's minor version number? i.e. 0.x.0
  int32 minor_version = 5;
  // What is this version's patch version number? i.e. 0.0.x
  int32 patch_version = 6;
  // What is this version's prerelease version number, if applicable? i.e. 0.0.0.x
  google.protobuf.Int32Value prerelease_version = 7;

  // Give me the actor bundles of this app
  repeated devvit.plugin.buildpack.Bundle actor_bundles = 8;

  // What should go in this version's about chunk? (Comes from README.md by default.)
  string about = 9;

  // Whether we should not create a default playtest subreddit for this app
  bool prevent_playtest_subreddit_creation = 10;

  // Any marketing information for this app version, if available
  optional app_version.info.AppVersionMarketingInfo marketing_info = 11;

  // If this app version is a Devvit Web app, this field is expected to contain
  // a `AppConfig` parsed from the `devvit.json` used by the app.
  optional string devvit_json = 12;

  // Size of the source code archive for this app version, if available. If this field is populated,
  // then the response will also contain a presigned URL and headers to upload the source code
  // archive to.
  optional int32 source_size = 13;
}

// Used to send an app's slug and version; the object equivalent of "my-app@1.2.3"
message AppSlugAndVersion {
  // What's the slug of the app we're looking for?
  string slug = 1;
  // What version are you looking for? Can be '1.2.3[.4]' or 'latest'.
  string version = 2;
}

// Used to update an existing app version's information. If a field is optional, omitting it will
// leave its value unchanged.
message AppVersionUpdateRequest {
  // What is the ID of the version you want to update?
  string id = 1;
  // How visible should the version be?
  info.OptionalVersionVisibility visibility = 2;
  // What installation types are allowed for this app?
  reserved 3;
  repeated info.InstallationType valid_install_types = 4;
  // What should go in this version's about chunk?
  google.protobuf.StringValue about = 5;

  info.ComputePool pool = 6;

  reserved 7; // removed

  // Version information is not editable.
  // Upload time is not editable.
  // Build status and timestamp are editable only by the build system, not via API.

  // The actor list is not editable.
}

// Get a list of valid installation locations for a given app version, optionally with
// paging info.
message ValidInstallLocationsRequest {
  // What is the ID of the app version you want to get valid install locations for?
  string id = 1;
  // If present, specifies what page of the response data you're asking for.
  repeated InstallLocationPageInfo page_info = 2;
}

// For a given install location type, give me requests before or after a given cursor.
message InstallLocationPageInfo {
  // The type of installation we're paging over
  info.InstallationType type = 1;
  // The cursor to start or end at
  oneof cursor {
    /**
     * Show me results before this startCursor.
     * @deprecated - Going backwards doesn't work; go forwards instead.
     */
    string before = 2;
    // Show me results after this endCursor.
    string after = 3;
  }
}

// endregion

// region Response types

// Contains the basic information about an app version, as well as the app it belongs to, the
// actors contained in the app, and any installations of the app.
message FullAppVersionInfo {
  info.AppVersionInfo app_version = 1;
  app.info.AppInfo app = 2;
  repeated actor.ActorTypeInfo actor_types = 3;
  repeated installation.InstallationInfo installations = 4;
}

// Lists all valid installation types and locations for a given app.
// Logic for this response:
// For each install type:
// - the type we're talking about
// - an array of valid install locations
message ValidInstallLocationsResponse {
  repeated InstallLocationInfo locations = 1;
}

// Gives an installation type, and list all valid installation locations matching that type.
message InstallLocationInfo {
  // The type of installation we're providing locations for
  info.InstallationType type = 1;
  // The list of valid install locations
  repeated InstallLocationDetails locations = 2;
  // Paging info for the response, if applicable
  optional PageInfo page_info = 3;
}

// Details each valid install location, and if there's already an install there or not.
message InstallLocationDetails {
  // The thing ID of the valid install location
  string thing_id = 1;
  // The name of the valid install location
  string name = 2;
  // If present, gives the UUID of an installation of the app in question that already exists in this location.
  google.protobuf.StringValue existing_install_id = 3;
  // The icon or avatar for the install location
  google.protobuf.StringValue icon = 4;
}

// Used to provide paging info about a response. This mirrors the PageInfo type in GQL.
message PageInfo {
  // When paginating forwards, are there more items?
  bool has_next_page = 1;
  /**
   * When paginating backwards, are there more items?
   * @deprecated - Going backwards doesn't work; go forwards instead.
   */
  bool has_previous_page = 2;
  /**
   * When paginating backwards, the cursor to continue.
   * @deprecated - Going backwards doesn't work; go forwards instead.
   */
  string start_cursor = 3;
  // When paginating forwards, the cursor to continue.
  string end_cursor = 4;
}

message GetAppVersionBundleResponse {
  message BundleInfo {
    string actor = 1;
    devvit.runtime.LinkedBundle bundle = 2;
  }
  repeated BundleInfo actor_bundles = 1;
}
// endregion
