//flynt-disable string-format-uri-forbidden

syntax = "proto3";

package com.wixpress.appservice.api;


import "google/protobuf/wrappers.proto";
import "google/api/annotations.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";
import "wix/api/validations.proto";
import "wix/api/annotations.proto";
import "wix/api/callback.proto";
import "wix/api/permissions.proto";
import "wix/api/entity.proto";
import "components_messages.proto";
import "webhooks_messages.proto";
import "permissions_messages.proto";
import "listingInfo_messages.proto";
import "versions_messages.proto";
import "translations_data_messages.proto";
import "pricing_model/pricing_model_messages.proto";
import "wix/common/paging.proto";
import "com/wixpress/appservice/api/components_catalog_type.proto";

message UpdateCompanyIdRequest {
  string app_id = 1 [(wix.api.format) = GUID];
  string company_id = 2 [(wix.api.format) = GUID];
}

message GetAppsByCompanyRequest {
  string company_id_or_slug = 1;
  google.protobuf.StringValue language_code = 2;
}

message TestYourAppRequest {
  string app_id = 1 [(wix.api.format) = GUID]; // the app id.
  // Optional version, will not create a version if this is passed
  google.protobuf.StringValue version = 2;
}

message TestYourAppResponse {
  // Either the newly created version or the version that was passed
  string version = 1;
}

message GetAppsByEmailRequest {
  string email = 1 [(.wix.api.format) = EMAIL, (.wix.api.pii) = true];
  string signature = 2;
}

message GetAppsByEmailResponse {
  // All apps belogning to this email
  repeated GetAppInfoResponse apps = 1;
  // Details about the user behind the email
  UserInfo userInfo = 2;
}

message UserInfo {
  string first_name = 1 [(.wix.api.pii) = true];
  string last_name = 2 [(.wix.api.pii) = true];
}

message CreateAppRequest {
  string name = 1 [(wix.api.minLength) = 1, (wix.api.maxLength) = 50]; // The app name, unique in user scope (user can't have two apps with the same name)
  google.protobuf.StringValue app_namespace = 2 [(wix.api.minLength) = 4, (wix.api.maxLength) = 255]; // A unique, immutable namespace containing only letters and numbers in camel case format
  Classification classification = 3; //This field differentiates the different type of apps
  google.protobuf.StringValue company_id = 4; // The companyId the app belongs to. if not provided, determined by the user.
}

message CreateAppResponse {
  string app_id = 1 [(wix.api.readOnly) = true, (wix.api.format) = GUID]; // When the app successfully created, this is its ID, use this to query the app in the future
}

message GetAppRequest {
  string app_id = 1 [(wix.api.format) = GUID]; // the app id.
  google.protobuf.StringValue language_code = 2; //required language code.
}

message UpdatePublishRequest {
  string app_id = 1 [(wix.api.format) = GUID]; // the app id.
  bool is_published = 2 [deprecated = true]; // please use version status
  string signature = 3;
}

message UpdateWixAppRequest {
  string app_id = 1 [(wix.api.format) = GUID]; // the app id.
  bool is_wix_app = 2;
}

message UpdateHideFromManagedAppsRequest {
  string app_id = 1 [(wix.api.format) = GUID]; // the app id.
  bool hide_from_managed_apps = 2;
}

message GetAppByVersionRequest {
  string app_id = 1 [(wix.api.format) = GUID]; // the app id.
  string version = 2 [(wix.api.minLength) = 1]; // the app version, formatted as xx.xx.xx. OPTIONAL
}

message GetOldBulkRequest {
  repeated string app_keys = 1; // either appId or appId:version
}

message GetAppResponse {
  string app_id = 1 [(wix.api.readOnly) = true, (wix.api.format) = GUID];
  string name = 2 [(wix.api.minLength) = 1];
  google.protobuf.StringValue icon_url = 3 [(wix.api.format) = URI]; // App's icon, to be displayed in UI
  google.protobuf.StringValue latest_version = 5; // App's latest GA version, formatted as xx.xx.xx
  AppData data = 6; // App data relating to this version, including all components etc
  repeated AppWebhook webhooks = 8;
  bool is_published = 9 [deprecated = true]; // please use app status
  bool is_wix_app = 10;
  google.protobuf.Timestamp date_created = 11;
  VersionStatus app_status = 12; //application status calculated from app versions status
  google.protobuf.BoolValue is_editable = 13;
  AppAuthData auth_data = 14;
  ContactEmails contact_emails = 15;
  google.protobuf.StringValue first_publish_date = 16;
  google.protobuf.StringValue release_notes = 17;
  bool is_standalone = 18;
  bool is_core_app = 19;
  google.protobuf.StringValue app_namespace = 20;
  Classification classification = 21; // classification of the app
}

message ContactEmails {
  repeated string support_emails = 1 [(wix.api.format) = EMAIL];
  repeated string urgent_emails = 2 [(wix.api.format) = EMAIL];
  repeated string billing_emails = 3 [(wix.api.format) = EMAIL];
}

message GetAppSnapshotResponse {
  string app_id = 1 [(wix.api.readOnly) = true, (wix.api.format) = GUID];
  string name = 2 [(wix.api.minLength) = 1];
  google.protobuf.StringValue icon_url = 3 [(wix.api.format) = URI]; // App's icon, to be displayed in UI
  google.protobuf.StringValue latest_version = 5; // App's latest GA version, formatted as xx.xx.xx
  repeated Component components = 6; // App data relating to this version, including all components etc
  repeated PermissionWithStatus permissions = 7;
  repeated AppWebhook webhooks = 8;
  AppAuthData auth_data = 9;
  bool is_published = 10 [deprecated = true]; // please use app status
  bool is_wix_app = 11;
  google.protobuf.Timestamp date_created = 12;
  VersionStatus app_status = 13; //application status calculated from app versions status
  google.protobuf.BoolValue is_editable = 14; // Will be false when the app was submitted
  google.protobuf.Struct app_json_old = 15; // Relevant for migrated apps only
  google.protobuf.StringValue latest_publish_version = 16;
  google.protobuf.StringValue latest_approved_version = 17;
  bool hide_from_managed_apps = 18; // if true, app will not show on the managed apps page
  ContactEmails contact_emails = 19;
  google.protobuf.StringValue first_publish_date = 20;
  google.protobuf.StringValue app_namespace = 21 [(wix.api.readOnly) = true]; // the unique namespace for this app
  bool is_standalone = 22; // true if and only if the app can be installed without requiring other apps
  bool is_core_app = 23; // true if and only if the apps are core service apps
  bool is_archived = 24; // true if and ony if the app is archived
  Classification classification = 25; // classification of the app
  google.protobuf.StringValue account_id = 26; // accountId the app belongs to
}

message GetOldAppResponse {
  google.protobuf.Struct app = 1; // This DTO is an equivalent of AppEditingDTO
}

message GetOldBulkResponse {
  // keys are appId:string (VersionedAppKey) and values are equivalent of AppEditingDTO
  map<string, google.protobuf.Struct> apps = 1;
}

message AppData {
  string version = 1; // The app version returned, formatted as xx.xx.xx
  repeated Component components = 2; // Component array for this app (and this version), each components is of type ....
  repeated Permission permissions = 3;
  AppListing app_listing = 4 [deprecated = true]; // use "app_listings" instead. todo: remove when client is ready
  repeated AppListing app_listings = 5; // listings for all languages
  repeated pricing.PricingModel pricing_models = 6;
  repeated TranslationData translation_data = 7;
  VersionStatus status = 8;
}

message GetDeveloperAppsRequest {
  // Whether the apps should return with their components (not working ATM)
  bool withComponents = 1;
  wix.common.Paging paging = 2; // pagination data
}

message GetDeveloperAppsResponse {
  repeated GetAppInfoResponse apps = 1; // list of app.
}

message GetAppInfoResponse {
  string app_id = 1 [(wix.api.readOnly) = true, (wix.api.format) = GUID];
  string name = 2 [(wix.api.minLength) = 1];
  google.protobuf.StringValue icon_url = 3 [(wix.api.format) = URI]; // App's icon, to be displayed in UI
  google.protobuf.StringValue latest_version = 4; // App's latest GA version, formatted as xx.xx.xx
  bool is_published = 5 [deprecated = true]; // please use app status
  bool is_wix_app = 6;
  google.protobuf.Timestamp date_created = 7;
  VersionStatus app_status = 8; //application status calculated from app versions status
  google.protobuf.BoolValue is_editable = 9;
  repeated Component components = 10;
  bool containsRedirectUrls = 11;
  google.protobuf.StringValue companyId = 12;
  bool hide_from_managed_apps = 13;
  bool is_standalone = 14;
  google.protobuf.StringValue api_key_identifier = 15; // for API Keys apps, this field will hold the last 6 chars of the key
  google.protobuf.StringValue account_id = 16; // the account id of the app creator
  Classification classification = 17; // classification of the app
}

message GetAllAppsResponse {
  string app_id = 1 [(wix.api.readOnly) = true, (wix.api.format) = GUID];
  string name = 2 [(wix.api.minLength) = 1];
  google.protobuf.StringValue icon_url = 3 [(wix.api.format) = URI]; // App's icon, to be displayed in UI
  google.protobuf.StringValue latest_version = 4; // App's latest GA version, formatted as xx.xx.xx
  bool is_published = 5 [deprecated = true]; // please use app status
  bool is_wix_app = 6;
  google.protobuf.Timestamp date_created = 7;
  string developer_id = 8 [(wix.api.format) = GUID];
  VersionStatus app_status = 9; //application status calculated from app versions status
  google.protobuf.BoolValue is_editable = 10;
}

// Representation of the key->value pairs in the app-webhook-secrets-store
message AppWebhookSecretMessage {
  string key = 1; // key = appId
  AppWebhookSecretMessageValue value = 2;
}

message AppWebhookSecretMessageValue {
  string secret = 1;
  google.protobuf.StringValue privateKey = 2;
}

// Representation of the key->value pairs in the app-secrets-store
message AppSecretMessage {
  string key = 1; // key = appId
  AppSecretMessageValue value = 2;
}

message AppSecretMessageValue {
  string secret = 1;
  google.protobuf.StringValue secondary_app_secret = 2;
}

message GetAppSecretRequest {
  string app_id = 1 [(wix.api.format) = GUID];
}

message GetAppSecretResponse {
  string app_secret = 1; // Used to create signed instances/authenticate with oauth provider
  string webhooks_secret = 2; // Deprecated
  google.protobuf.StringValue webhooks_public_key = 3; // Used to sign webhooks that are sent to tpas
}

message GetAppServerAuthRequest {
  string app_id = 1 [(wix.api.format) = GUID];
}

message GetAppServerAuthResponse {
  string app_secret = 1; // Used to create signed instances/authenticate with oauth provider
  bool is_wix_app = 2;
}

message GetAppsInfoRequest {
  repeated string apps_id = 1 [(wix.api.format) = GUID];
}

message GetAppsInfoResponse {
  repeated GetAppInfoResponse apps = 1; // list of app info
}

message GetAppsResponse {
  repeated GetAllAppsResponse apps = 1; // list of app info
  google.protobuf.Int32Value total = 2; // Number of all apps existing
}

message GetAppsRequest {
  google.protobuf.Int32Value page = 1;
  google.protobuf.Int32Value limit = 2;
  google.protobuf.StringValue signature = 3;
}

message ArchiveAppRequest {
  string app_id = 1 [(wix.api.format) = GUID];
  bool archive = 2;
}


message FixVendorIdRequest {
  repeated string app_ids = 1 [(wix.api.format) = GUID];
}

message FixVendorIdResponse {

}

message GetAppsByAppNameRequest {
  string app_name = 1 [(wix.api.minLength) = 1, (wix.api.maxLength) = 255];
  string signature = 2;
  google.protobuf.Int32Value page = 3;
  google.protobuf.Int32Value limit = 4;
}

message GetAppsByAppNameResponse {
  repeated GetAppInfoResponse apps = 1;
  google.protobuf.Int32Value total = 2;
}

message UpdateAppJsonRequest {
  string app_id = 1 [(wix.api.format) = GUID];
  google.protobuf.Struct app_json = 2;
}

message DeleteAppDeprecatedRequest {
  string app_id = 1 [(wix.api.format) = GUID];
  bool delete = 2;
}

message DeleteAppDeprecatedResponse {
  string new_app_id = 1 [(wix.api.readOnly) = true, (wix.api.format) = GUID];
  string deleted_records = 2;
}

message FixAppsCompanyMappingRequest {
}

message FixAppsCompanyMappingResponse {
}

message Property {
  string key = 1;
  google.protobuf.Value value = 2;
}

message UpdateAppPropertyRequest {
  // the app id
  string app_id = 1 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
  // property to update
  Property property = 2;
}

message UpdateAppPropertyResponse {}

message GetAllAppsByPropertyRequest {
  // properties to filter by
  repeated Property properties = 1;
  // Paging - default limit is 50, default offset is 0
  wix.common.Paging paging = 2;
}

message GetAllAppsByPropertyResponse {
  // List of app ids that matching the property
  repeated string app_ids = 1 [(wix.api.format) = GUID];
  // Metadata on this page
  wix.common.PagingMetadata paging_metadata = 2;
}

message GetAppForInstallationRequest {
  string app_id = 1 [(wix.api.format) = GUID];
  google.protobuf.StringValue version = 2;
}

message getDataForInstallationRequest {
  string app_id = 1 [(wix.api.format) = GUID];
  google.protobuf.StringValue version = 2;
}

message LatestMarketVersionRequest {
  string app_id = 1 [(wix.api.format) = GUID];
  google.protobuf.StringValue language_code = 2;
}

message LatestMarketVersionResponse {
  MarketVersion appMarketVersion = 1;
}

message ChangeAppIdRequest {
  string from_app_id = 1 [(wix.api.format) = GUID];
  string to_app_id = 2 [(wix.api.format) = GUID];
}

message ChangeAppIdResponse {
}

message GetAppForInstallationResponse {
  GetAppResponse app = 1;
  string version_to_install = 2;
}

message getDataForInstallationResponse {
  repeated Component components = 1; // Component array for this app (and this version), each components is of type ....
  AppAuthData auth_data = 2;
  string version_to_install = 3; // the version to install the app
  repeated Permission permissions = 4;
}

message BulkDeleteAutomationAppsRequest {
  repeated string app_ids = 1;
}

message BulkDeleteAutomationAppsResponse {
  repeated string deleted_app_ids = 1;
}

message RestoreFromVersionRequest {
  string app_id = 1 [(wix.api.format) = GUID];
  string version = 2;
}

message RestoreFromVersionResponse {
}

message GetMarketAppRequest {
  string app_id = 1 [(wix.api.format) = GUID]; // the app id.
  string language_code = 2;
  google.protobuf.StringValue version = 3;
}

message UpdateContactEmailsRequest {
  string app_id = 1 [(wix.api.format) = GUID];
  ContactEmails contact_emails = 2;
}

message UpdateContactEmailsResponse {
}

message SetLatestVersionRequest {
  repeated LatestVersionForApp latest_versions_for_apps  = 1;
}

message LatestVersionForApp {
  string app_id = 1 [(wix.api.format) = GUID];
  string latest_version = 2;
}

message SetLatestVersionResponse {
}

message FetchAppsWithIncorrectLatestVersionRequest {
}

message FetchAppsWithIncorrectLatestVersionResponse {
  repeated LatestVersionForApp correct_versions_for_apps = 1;
}


message SetAppNamespaceRequest {
  string app_id = 1 [(wix.api.format) = GUID];
  // A unique, immutable namespace containing only letters and numbers in camel case format
  string app_namespace = 2 [(wix.api.minLength) = 4, (wix.api.maxLength) = 255];
}

message SetAppNamespaceResponse {
}

message AppGlobalsChanged {
  string app_id = 1 [(wix.api.format) = GUID];
  Data data = 2;

  message Data {
    bool is_core_app = 1;
    google.protobuf.StringValue app_namespace = 2;
    bool is_wix_app = 3;
    bool is_archived = 4;
  }
}

message AppChangedEvent {
  App app = 1;
  Action action = 2;
  repeated string updated_fields = 3;

  enum Action {
    CREATED = 0;
    UPDATED = 1;
    DEPRECATED = 2;
    DELETED = 3;
  }
}

// Fake main entity - once we'll refactor this service - we'll need to fill the properties here and start using it as the main service entity
message App {
  option (.wix.api.entity) = {
    fqdn: "wix.devcenter.apps.v1.app_old"
    segment: USERS
  };

  string id = 1 [(wix.api.format) = GUID]; //The id of the app
  string name = 2; //The name of the App
  google.protobuf.StringValue icon_url = 3 [(wix.api.format) = URI]; // App's icon, to be displayed in UI
  google.protobuf.StringValue latest_version = 4; // App's latest GA version, formatted as xx.xx.xx
  bool is_wix_app = 5; //Is it a Wix app?
  string app_status = 6; //application status calculated from app versions status
  bool is_editable = 7; //Can the app be updated?
  string app_secret = 8; // Used to create signed instances/authenticate with oauth provider
  google.protobuf.StringValue webhooks_public_key = 9; // Used to sign webhooks that are sent to tpas
  bool is_core_app = 10; //Is it a core Wix app?
  google.protobuf.StringValue namespace = 11; //The namespace of the App
  google.protobuf.StringValue team_id = 12 [(wix.api.format) = GUID]; //The team id which the App belongs to
  google.protobuf.StringValue company_id = 13; //The company id which the App belongs to
  google.protobuf.StringValue classification = 14; //The type of App
  bool hide_from_managed_apps = 15; // if true, app will not show on the managed apps page
  bool is_archived = 16; // true if and ony if the app is archived
  google.protobuf.StringValue first_publish_date = 17; //updates only one time, when the app is published for the first time
  ContactEmails contact_emails = 18; //represents all the contactEmails
}

message GetAppIdsOrderedByFirstPublishDateRequest {
    int32 daysDiff = 1; // retrieve apps that were published less than daysDiff days ago.
}

message GetAppIdsOrderedByFirstPublishDateResponse {
  repeated string app_ids = 1; // list of published app ids sorted by their first publish date.
}
