syntax = "proto3";

package wix.devcenter.components.translation.v1;
option java_package = "com.wixpress.devcenter.components.translation.v1";

import "google/protobuf/field_mask.proto";
import "google/api/annotations.proto";
import "google/protobuf/wrappers.proto";
import "wix/api/annotations.proto";
import "wix/api/validations.proto";
import "wix/api/subscription.proto";
import "com/wixpress/vi/localization/translator/content-translation-service.proto";
import "wix/common/query.proto";
import "wix/api/action_payload.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/components/translation/v1/component_translation.proto";
import "google/protobuf/empty.proto";
import "translations_messages.proto";
import "wix/common/domainevents/domainevents.proto";
import "wix/devcenter/apps/components/v1/component.proto";
import "wix/devcenter/apps/translations/v1/app_translation.proto";
import "components_catalog_data.proto";
import "wix/rich_content/v1/rich_content.proto";


/**
  Manages ComponentTranslations
 */
service ComponentsTranslationService {
  option (.wix.api.service_maturity) = BETA;
  option (.wix.api.service_exposure) = PUBLIC;
  option (wix.api.service_entity).message = "wix.devcenter.components.translation.v1.ComponentTranslation";

  /**
    Get a ComponentTranslation by app id, component id, version and language code
   */
  rpc GetComponentTranslation (GetComponentTranslationRequest) returns (GetComponentTranslationResponse) {
    option (google.api.http).get = "/v1/component-translations/{component_id}";
    option (.wix.api.crud) = {
      method: GET_ITEM
    };
    option (.wix.api.permission) = {
      name: "DEVCENTER.READ_COMPONENTS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.READ_COMPONENT"
      type: MANUAL
    };
  }

  /**
  Get a ComponentTranslation bulk by app id, component id, version and language code
 */
  rpc GetComponentTranslationBulk (GetComponentTranslationBulkRequest) returns (GetComponentTranslationBulkResponse) {
    option (google.api.http).post = "/v1/component-translations"; // using post to get Repeated fields
    option (.wix.api.permission) = {
      name: "DEVCENTER.READ_COMPONENTS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.READ_COMPONENT"
      type: MANUAL
    };
  }

  /**
  Get a ExperimentTranslation by app id and language code
 */
  //flynt-disable http-mapping-breaking-change
  rpc GetExperimentTranslations (GetExperimentTranslationsRequest) returns (GetExperimentTranslationsResponse) {
    option (wix.api.exposure) = INTERNAL;
    option (.wix.api.permission) = {
      name: "DEVCENTER.READ_COMPONENTS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.READ_COMPONENT"
      type: MANUAL
    };
  }

  /**
    Sets the values for both component keys as well as additional keys.
    This is a partial update, where keys not sent are not updated.
    Sending an empty value for a key will set it as not translated.
   */
  rpc TranslateKeys (TranslateKeysRequest) returns (TranslateKeysResponse) {
    option (google.api.http).patch = "/v1/component-translations/{component_id}";
    option (.wix.api.required) = "TranslateKeysRequest.app_id";
    option (.wix.api.required) = "TranslateKeysRequest.component_id";
    option (.wix.api.permission) = {
      name: "DEV_CENTER.MANAGE_COMPONENTS"
      type: MANUAL
    };
    option (.wix.api.callback) = {
      event_type: UPDATED
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.WRITE_COMPONENT_TRANSLATIONS"
      type: MANUAL
    };
  }

  /**
  Sets the values for experiment component keys.
  This is a partial update, where keys not sent are not updated.
  Sending an empty value for a key will set it as not translated.
 */
  //flynt-disable http-mapping-breaking-change
  rpc TranslateExperimentKeys (TranslateExperimentKeysRequest) returns (TranslateExperimentKeysResponse) {
    option (wix.api.exposure) = INTERNAL;
    option (.wix.api.required) = "TranslateExperimentKeysRequest.app_id";
    option (.wix.api.required) = "TranslateExperimentKeysRequest.component_id";
    option (.wix.api.permission) = {
      name: "DEV_CENTER.MANAGE_COMPONENTS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.WRITE_COMPONENT_TRANSLATIONS"
      type: MANUAL
    };
    option (.wix.api.callback) = {
      event_type: UPDATED
    };
  }

  /*
  Get the component in a foreign language, along with its additional fields
   */
  //flynt-disable http-mapping-breaking-change
  rpc GetTranslatedComponent (GetTranslatedComponentRequest) returns (GetTranslatedComponentResponse) {
    option (wix.api.exposure) = INTERNAL;
    option (.wix.api.permission) = {
      name: "DEVCENTER.READ_COMPONENTS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.READ_COMPONENT"
      type: MANUAL
    };
  }

  /*
  Get translated component data of experiments in a foreign language
 */
  //flynt-disable http-mapping-breaking-change
  rpc GetTranslatedExperiments (GetTranslatedExperimentsRequest) returns (GetTranslatedExperimentsResponse) {
    option (wix.api.exposure) = INTERNAL;
    option (.wix.api.permission) = {
      name: "DEVCENTER.READ_COMPONENTS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.READ_COMPONENT"
      type: MANUAL
    };
  }

  /*
  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
    };
  }

  /*
  Listen to smartling translation events
   */
  rpc ConsumeContentTranslatedInContentService (com.wixpress.vi.localization.translator.ContentTranslatedEvent) returns (google.protobuf.Empty) {
    option (wix.api.exposure) = PRIVATE;
    option (wix.api.subscription) = {
      topic: "translator.content-translated-event"
      segment: PUBLIC
    };
  }

  /*
  Listen to component translation events
   */
  rpc ConsumeKeyTranslatedInOldTranslationsServiceEvent (KeyTranslatedInOldTranslationsServiceEvent) returns (google.protobuf.Empty) {
    option (wix.api.exposure) = PRIVATE;
    option (wix.api.subscription) = {
      topic: "component-translated-in-old-service"
      segment: USERS
    };
  }

  /*
Consume experiments domain events
*/
  rpc ConsumeExperimentsDomainEvents (wix.common.domainevents.DomainEvent) returns (google.protobuf.Empty) {
    option (wix.api.exposure) = PRIVATE;
    option (wix.api.subscription) = {
      entity: "wix.devcenter.components.experiments.v1.ComponentExperiment",
    };
  }

  /*
    Get bulk translated components
  */
  //flynt-disable http-mapping-breaking-change
  rpc GetTranslatedComponentBulk (GetTranslatedComponentBulkRequest) returns (GetTranslatedComponentBulkResponse) {
    option (wix.api.exposure) = INTERNAL;
    option (.wix.api.permission) = {
      name: "DEVCENTER.READ_COMPONENTS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.READ_COMPONENT"
      type: MANUAL
    };
  }

  /*
    Translate components
  */
  //flynt-disable http-mapping-breaking-change
  rpc TranslateComponents (TranslateComponentsRequest) returns (TranslateComponentsResponse) {
    option (wix.api.exposure) = INTERNAL;
    option (.wix.api.permission) = {
      name: "DEVCENTER.READ_COMPONENTS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.READ_COMPONENT"
      type: MANUAL
    };
  }

  rpc TranslateComponentsBulk (TranslateComponentsBulkRequest) returns (TranslateComponentsBulkResponse) {
    option (wix.api.exposure) = INTERNAL;
    option (.wix.api.permission) = {
      name: "DEVCENTER.READ_COMPONENTS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.READ_COMPONENT"
      type: MANUAL
    };
  }

  /*
  Consume new components in order to scan them for translation
   */
  rpc ConsumeComponentsDomainEvents (wix.common.domainevents.DomainEvent) returns (google.protobuf.Empty) {
    option (wix.api.exposure) = PRIVATE;
    option (wix.api.subscription) = {
      entity: "wix.devcenter.apps.components.v1.Component",
    };
  }

  /*
  Listen to component translation events in order to update smartling
   */
  rpc ConsumeTranslationAddedDomainEvents (wix.common.domainevents.DomainEvent) returns (google.protobuf.Empty) {
    option (wix.api.exposure) = PRIVATE;
    option (wix.api.subscription) = {
      entity: "wix.devcenter.components.translation.v1.ComponentTranslation",
    };
  }

  /*
Trigger scanning components. used in migration only
*/
  rpc TriggerComponentScan (TriggerComponentScanRequest) returns (TriggerComponentScanResponse) {
    option (wix.api.exposure) = PRIVATE;
    option (wix.api.deprecated) = {};
  }

  option (wix.api.event) = {
    topic: "add-component-translation"
    segment: USERS
    payload: "wix.devcenter.components.translation.v1.TranslatedComponentEvent"
  };

  /*
    Update component translation activation
  */
  rpc UpdateComponentTranslationActivation (UpdateComponentTranslationActivationRequest) returns (UpdateComponentTranslationActivationResponse) {
    option (google.api.http).post = "/v1/component-translations/activation/{app_id}/{component_id}/{activated}";
    option (.wix.api.permission) = {
      name: "DEVCENTER.WRITE_COMPONENTS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.WRITE_APP_TRANSLATIONS"
      type: MANUAL
    };
  }

  /*
   Update component translation activation
 */
  rpc ActivateAllLanguagesForComponent (ActivateAllLanguagesForComponentRequest) returns (ActivateAllLanguagesForComponentResponse) {
    option (google.api.http).post = "/v1/component-translations/activation/{app_id}/{component_id}";
    option (.wix.api.permission) = {
      name: "DEVCENTER.MANAGE_COMPONENTS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.WRITE_APP_TRANSLATIONS"
      type: MANUAL
    };
  }

  /*
    Update all app's components translation activation
 */
  rpc UpdateComponentsTranslationActivation (UpdateComponentsTranslationActivationRequest) returns (UpdateComponentsTranslationActivationResponse) {
    option (google.api.http).post = "/v1/component-translations/activation-by-app/{app_id}/{language_code}/{activated}";
    option (.wix.api.permission) = {
      name: "DEVCENTER.MANAGE_COMPONENTS"
      type: MANUAL
    };
    option (.wix.api.additional_permission) = {
      name: "DEV_CENTER.WRITE_APP_TRANSLATIONS"
      type: MANUAL
    };
  }

  /*
    Update all app's components translation activation
 */
  rpc SyncAllComponentKeysWithSmartling (SyncAllComponentKeysWithSmartlingRequest) returns (SyncAllComponentKeysWithSmartlingResponse) {
    option (google.api.http).post = "/v1/component-translations/sync-smartling/{app_id}";
    option (wix.api.exposure) = PRIVATE;
    option (.wix.api.permission) = {
      name: "DEVCENTER.MANAGE_COMPONENTS"
      type: MANUAL
    };
  }
}

// flynt-disable crud-get-item-message-validation
message GetComponentTranslationRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // app id of the translation
  string component_id = 2 [(.wix.api.format) = GUID]; // component id of the translation
  string language_code = 3 [(.wix.api.maxLength) = 4]; // 2 letter language code as seen in app-market
  int32 version = 4; // component version
}

message GetComponentTranslationResponse {
  ComponentTranslation component_translation = 1; // The retrieved component translation
}

message GetComponentTranslationBulkRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // app id of the translations
  string language_code = 2 [(.wix.api.maxLength) = 4]; // language code of the translations
  repeated ComponentVersion components_versions = 3 [(.wix.api.maxSize) = 100]; // the component versions to get translations for
}

message ComponentVersion {
  string component_id = 1 [(.wix.api.format) = GUID]; // component id
  int32 version = 2; // component version
}

message GetComponentTranslationBulkResponse {
  repeated ComponentTranslation component_translation = 1; // The retrieved component translations
}

message TranslateKeysRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // app id of the translation
  string component_id = 2 [(.wix.api.format) = GUID]; // component id of the translation
  string language_code = 3 [(.wix.api.maxLength) = 4]; // 2 letter language code, as seen in app market
  google.protobuf.Int32Value version = 4; // component version for the translation
  map<string, string> translations = 5; // translation keys and values. key represents the path in proto. value represents the translated value
  map<string, wix.rich_content.v1.RichContent> rich_content_translations = 6; // translation keys and values. key represents the path in proto. value represents the translated RichContent value
}

message TranslateKeysResponse {
  ComponentTranslation component_translation = 1; // The updated component translation
}

message TranslateExperimentKeysRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // app id of the translation
  string component_id = 2 [(.wix.api.format) = GUID]; // component id of the translation
  string language_code = 3 [(.wix.api.maxLength) = 4]; // 2 letter language code, as seen in app market
  map<string, string> translations = 5; // translation keys and values. key represents the path in proto. value represents the translated value
}

message TranslateExperimentKeysResponse {
  ExperimentTranslation experiment_translation = 1; // The updated component translation
}

message GetTranslatedComponentRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // app id of the translation
  string component_id = 2 [(.wix.api.format) = GUID]; // component id of the translation
  string language_code = 3 [(.wix.api.maxLength) = 4]; // 2 letter language code, as seen in app market
  google.protobuf.Int32Value version = 4; // component version for the translation
}

message GetTranslatedComponentResponse {
   apps.components.v1.Component component = 1; // The translated component
   map<string, string> additional_keys = 2; // the additional keys of the translation
}

message GetTranslatedComponentBulkRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // Components for this app
  repeated ComponentVersion components = 2 [(.wix.api.maxSize) = 100]; // Components to translate
  string language_code = 3 [(.wix.api.maxLength) = 4]; // Translation for this language
  bool consistent = 4; // Fetch consistent data
  bool translate_only_activated = 5; // translate only activated languages. if language is not activated - english will be returned
}

message GetTranslatedComponentBulkResponse {
  repeated TranslatedComponent translated_components = 1; // The translated component
}

message TranslateComponentsRequest {
  repeated apps.components.v1.Component components = 1 [(.wix.api.maxSize) = 100]; // Components to translate
  string language_code = 2 [(.wix.api.maxLength) = 4]; // Translation for this language
  bool consistent = 3; // Fetch consistent data
  bool translate_only_activated = 4; // translate only activated languages. if language is not activated - english will be returned
}

message TranslateComponentsResponse {
  repeated TranslatedComponent translated_components = 1; // The translated component
}

message TranslateComponentsBulkRequest {
  repeated apps.components.v1.Component components = 1 [(.wix.api.maxSize) = 100]; // Components to translate
  repeated string language_codes = 2 [(.wix.api.maxLength) = 4,(.wix.api.minSize) = 1, (.wix.api.maxSize) = 50]; // Translation for these language
  bool consistent = 3; // Fetch consistent data
  bool translate_only_activated = 4; // translate only activated languages. if language is not activated - english will be returned
}

message TranslateComponentsBulkResponse {
  map<string, TranslatedComponents> translated_components_per_language = 1; // the additional keys of the translation
}

message TranslatedComponents {
  repeated TranslatedComponent translated_components = 1 [(.wix.api.maxSize) = 100]; // The translated component
}

message KeyTranslatedInOldTranslationsServiceEvent {
  string app_id = 1 [(.wix.api.format) = GUID]; // Components for this app
  string component_id = 2 [(.wix.api.format) = GUID]; // component id of the translation
  string language_code = 3 [(.wix.api.maxLength) = 4]; // 2 letter language code, as seen in app market
  map<string, string> translations = 5; // keys and values of the translation
}

message TranslatedComponentEvent {
  apps.components.v1.Component component = 1; // The translated component
  map<string, string> additional_keys = 2; // the additional keys of the translation
  string language_code = 3 [(.wix.api.maxLength) = 4]; // 2 letter language code, as seen in app market
}

message TriggerComponentScanRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // app for the component
  string component_id = 2 [(.wix.api.format) = GUID]; // Component for this app
}

message TriggerComponentScanResponse {
}

message UpdateComponentTranslationActivationRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // Components for this app
  string component_id = 2 [(.wix.api.format) = GUID]; // component id of the translation
  string language_code = 3 [(.wix.api.maxLength) = 4]; // 2 letter language code, as seen in app market
  bool activated = 4; // indicates weather the component translation will be published
}

message UpdateComponentTranslationActivationResponse {
}

message ActivateAllLanguagesForComponentRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // Components for this app
  string component_id = 2 [(.wix.api.format) = GUID]; // component id of the translation
}

message ActivateAllLanguagesForComponentResponse {

}

message UpdateComponentsTranslationActivationRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // Components for this app
  string language_code = 3 [(.wix.api.maxLength) = 6]; // language code, as seen in app market
  bool activated = 4; // indicates weather the component translation will be published
}

message UpdateComponentsTranslationActivationResponse {
}

message GetExperimentTranslationsRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // Components for this app
  string language_code = 2 [(.wix.api.maxLength) = 4]; // language code, as seen in app market
}

message GetExperimentTranslationsResponse {
  repeated ExperimentTranslation experiment_translations = 1;
}

message GetTranslatedExperimentsRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // Components for this app
  string language_code = 2 [(.wix.api.maxLength) = 4]; // language code, as seen in app market
  bool consistent = 3; // Should perform consistent query
}

message GetTranslatedExperimentsResponse {
  map<string, com.wixpress.appservice.api.ComponentData> translated_component_data = 1; // a map from component id to translated component data which holds the translated values
}

message SyncAllComponentKeysWithSmartlingRequest {
  string app_id = 1 [(.wix.api.format) = GUID]; // Components for this app
  google.protobuf.StringValue component_id = 2 [(.wix.api.format) = GUID]; // component id of the translation
}

message SyncAllComponentKeysWithSmartlingResponse {}

message TranslationFailed {
  option (wix.api.action_payload).custom_slug = "translation_failed";
  string failure_reason = 1 [(wix.api.maxLength) = 1024]; // The relevant message for the failure
  ComponentTranslation current_translation = 2; // Current existing component translation
  ComponentTranslation attempted_translation = 3; // Attempted translation that was failed to be applied
}