syntax = "proto3";

package wix.devcenter.apps.translations.v1;
option java_package = "com.wixpress.devcenter.apps.translations.v1";

import "google/protobuf/field_mask.proto";
import "google/api/annotations.proto";
import "wix/api/annotations.proto";
import "wix/api/validations.proto";
import "wix/common/query.proto";
import "wix/api/entity.proto";
import "wix/api/permissions.proto";
import "wix/api/callback.proto";
import "wix/http/field_mask.proto";
import "wix/devcenter/apps/translations/v1/app_translation.proto";
import "wix/common/paging.proto";
import "wix/common/domainevents/domainevents.proto";
import "wix/api/subscription.proto";
import "google/protobuf/empty.proto";
import "translations_messages.proto";

/**
  Manages AppTranslations
 */
service AppTranslationsService {
  option (.wix.api.service_maturity) = BETA;
  option (.wix.api.service_exposure) = PUBLIC;
  option (wix.api.service_entity).message = "wix.devcenter.apps.translations.v1.AppTranslation";

  /**
    Creates a new AppTranslation
   */
  rpc CreateAppTranslation (CreateAppTranslationRequest) returns (CreateAppTranslationResponse) {
    option (google.api.http).post = "/v1/app-translations";
    option (.wix.api.permission) = {
      name: "DEV_CENTER.MANAGE_APPS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.CREATE_APP_TRANSLATION"
      type: MANUAL
    };
    option (.wix.api.required) = "CreateAppTranslationRequest.app_translation";
    option (.wix.api.callback) = {
      event_type: CREATED
    };
    option (.wix.api.crud) = {
      method: CREATE
      create_options: {
        item_field: "app_translation"
      }
    };
  }

  /**
    Get list of AppTranslation by app id
   */
  rpc GetAppTranslations (GetAppTranslationsRequest) returns (GetAppTranslationsResponse) {
    option (google.api.http).get = "/v1/app-translations/{app_id}";
    option (.wix.api.permission) = {
      name: "DEV_CENTER.READ_APPS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.READ_APP_TRANSLATION"
      type: MANUAL
    };
    option (.wix.api.required) = "GetAppTranslationsRequest.app_id";
    option (.wix.api.crud) = {
      method: GET_ITEM
      get_options: {
        id_field: "app_id"
      }
    };
  }

  /**
    Get list of AppTranslation by app ids
   */
  rpc GetAppsTranslations (GetAppsTranslationsRequest) returns (GetAppsTranslationsResponse) {
    option (.wix.api.permission) = {
      name: "DEV_CENTER.READ_APP_TRANSLATION_SERVICE_LEVEL"
    };
  }

  /**
    Update the component translation activation. partial update
    Pass the app id for a successful update
   */
  rpc UpdateComponentsActivation (UpdateComponentsActivationRequest) returns (UpdateComponentsActivationResponse) {
    option (google.api.http).patch = "/v1/app-translations/components-activation/{app_translation.id}";
    option (.wix.api.permission) = {
      name: "DEV_CENTER.MANAGE_APPS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.WRITE_APP_TRANSLATION"
      type: MANUAL
    };
    option (.wix.api.required) = "UpdateComponentsActivationRequest.app_translation";
    option (.wix.api.callback) = {
      event_type: UPDATED
    };
    option (.wix.api.crud) = {
      method: UPDATE
      update_options: {
        item_field: "app_translation"
      }
    };
  }

  /**
    Update the market translation activation. partial update
    Pass the app id for a successful update
   */
  rpc UpdateMarketActivation (UpdateMarketActivationRequest) returns (UpdateMarketActivationResponse) {
    option (google.api.http).patch = "/v1/app-translations/market-activation/{app_translation.id}";
    option (.wix.api.permission) = {
      name: "DEV_CENTER.MANAGE_APPS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.WRITE_APP_TRANSLATION"
      type: MANUAL
    };
    option (.wix.api.required) = "UpdateMarketActivationRequest.app_translation";
    option (.wix.api.callback) = {
      event_type: UPDATED
    };
  }

  /*
    Consume events where app market add a language to an app
 */
  rpc ConsumeLanguageAddedToAppMarket (com.wixpress.appservice.api.LanguageAddedToAppEvent) returns (google.protobuf.Empty) {
    option (wix.api.exposure) = PRIVATE;
    option (wix.api.subscription) = {
      topic: "app-language-code-added"
      segment: USERS
    };
  }

  /*
    Consume events where app market updated a language in app
 */
  rpc ConsumeLanguageUpdatedInAppMarket (com.wixpress.appservice.api.LanguageUpdatedInAppEvent) returns (google.protobuf.Empty) {
    option (wix.api.exposure) = PRIVATE;
    option (wix.api.subscription) = {
      topic: "app-language-code-updated"
      segment: USERS
    };
  }

  /*
    Consume events for copy app languages
 */
  rpc ConsumeLanguagesCopyApp (com.wixpress.appservice.api.LanguagesCopyAppEvent) returns (google.protobuf.Empty) {
    option (wix.api.exposure) = PRIVATE;
    option (wix.api.subscription) = {
      topic: "app-language-code-copy"
      segment: USERS
    };
  }

  /*
    returns all Wix supported languages except English
  */
  rpc GetSupportedLanguages (GetSupportedLanguagesRequest) returns (GetSupportedLanguagesResponse) {
    option (google.api.http).get = "/v1/app-translations/supported-languages";
    option (.wix.api.permission) = {
      name: "DEV_CENTER.READ_APPS"
      type: MANUAL
    };
  }

  /**
   Consume App DomainEvents in order to add all languages to it
 */
  rpc ConsumeAppDomainEvents (wix.common.domainevents.DomainEvent) returns (google.protobuf.Empty) {
    option (wix.api.exposure) = PRIVATE;
    option (wix.api.subscription) = {
      entity: "wix.devcenter.apps.v1.App",
    };
  }
}

message CreateAppTranslationRequest {
  AppTranslation app_translation = 1; // AppTranslation to be created
}

message CreateAppTranslationResponse {
  AppTranslation app_translation = 1; // The created AppTranslation
}

message GetAppTranslationsRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // Id of the App to retrieve
}

message GetAppTranslationsResponse {
  repeated AppTranslation app_translation = 1; // The retrieved AppTranslations
}

message UpdateAppTranslationRequest {
  AppTranslation app_translation = 1; // AppTranslation to be updated
}

message UpdateComponentsActivationRequest {
  AppTranslation app_translation = 1; // AppTranslation to be updated, may be partial
}

message UpdateMarketActivationRequest {
  AppTranslation app_translation = 1; // AppTranslation to be updated, may be partial
}

message UpdateComponentsActivationResponse {
  AppTranslation app_translation = 1; // updated AppTranslation
}

message UpdateMarketActivationResponse {
  AppTranslation app_translation = 1; // updated AppTranslation
}

message UpdateAppTranslationResponse {
  AppTranslation app_translation = 1; // The updated AppTranslation
}

message GetSupportedLanguagesRequest {}

message GetSupportedLanguagesResponse {
  repeated Language languages = 1; // all supported languages
  repeated Language app_market_languages = 2; // all supported app market languages
}

message Language {
  string language_code = 1 [(wix.api.format) = LANGUAGE]; // two letter code ISO 639-1
  string language_name = 2 [(wix.api.maxLength) = 50]; // language name in English
}

message GetAppsTranslationsRequest {
  repeated string app_ids = 1 [(.wix.api.format) = GUID, (wix.api.minSize) = 1, (wix.api.maxSize) = 100]; // ids of the apps requested
}

message GetAppsTranslationsResponse {
  map<string, AllAppTranslations> app_translations_map = 1 [(wix.api.maxSize) = 100]; // map from app id to its translations

}
message AllAppTranslations {
  repeated AppTranslation apps_translations = 1 [(wix.api.maxSize) = 100]; //  The resulting app translations
}