syntax = "proto3";

package com.wixpress.vi.localization.translator;

import "com/wixpress/vi/localization/translator/content.proto";
import "wix/api/callback.proto";
import "wix/api/validations.proto";
import "wix/api/annotations.proto";
import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";
import "wix/api/entity.proto";

service ContentTranslationService {
    option (wix.api.service_entity).message = "com.wixpress.vi.localization.translator.ContentTranslatedEvent";
    // Event that fires when content is fully/partially translated for some locale
    option (wix.api.event) = {
       topic: "translator.content-translated-event"
       payload: "com.wixpress.vi.localization.translator.ContentTranslatedEvent"
   };

    // check for new translations for a single file, produces ContentTranslatedEvent
    rpc CheckForNewTranslationsForSingleContent (CheckForNewTranslationsForSingleContentRequest) returns (CheckForNewTranslationsForSingleContentResponse) {
        option (google.api.http).post = "/api/content-translation/v1/check-file/{config.smartling_project_id}";
        option (wix.api.exposure) = INTERNAL;
        option (wix.api.maturity) = ALPHA;
        option (wix.api.required) = "CheckForNewTranslationsForSingleContentRequest.config.smartling_project_id";
        option (wix.api.required) = "CheckForNewTranslationsForSingleContentRequest.content_uri";
        option (wix.api.callback) = {
           topic: "translator.content-translated-event"
           payload: "com.wixpress.vi.localization.translator.ContentTranslatedEvent"
       };
    }

    // check for new translations, produces ContentTranslatedEvent
    rpc CheckForNewTranslations (CheckForNewTranslationsRequest) returns (CheckForNewTranslationsResponse) {
        option (google.api.http).post = "/api/content-translation/v1/check/{config.smartling_project_id}";
        option (wix.api.exposure) = INTERNAL;
        option (wix.api.maturity) = ALPHA;
        option (wix.api.required) = "CheckForNewTranslationsRequest.config.smartling_project_id";
        option (wix.api.callback) = {
           topic: "translator.content-translated-event"
           payload: "com.wixpress.vi.localization.translator.ContentTranslatedEvent"
       };
    }

    // check for new translations for all the registered clients
    rpc CheckForNewTranslationsForAllClients (CheckForNewTranslationsForAllClientsRequest) returns (CheckForNewTranslationsForAllClientsResponse) {
        option (google.api.http).post = "/api/content-translation/v1/check-all";
        option (wix.api.exposure) = PRIVATE;
        option (wix.api.maturity) = ALPHA;
    }

}

message CheckForNewTranslationsForSingleContentRequest {
    // Configuration that defines a client
    ClientConfig config = 1;

    // The unique content uri provided during the upload flow
    string content_uri = 2;

    // Optional timestamp, used for getting translations that were modified after this time
    google.protobuf.Timestamp lastModifiedAfter = 3;
}

message CheckForNewTranslationsForSingleContentResponse {
}

message CheckForNewTranslationsRequest {
    // Configuration that defines a client
    ClientConfig config = 1;

    // Optional timestamp, used for getting translations that were modified after this time
    google.protobuf.Timestamp lastModifiedAfter = 2;
}

message CheckForNewTranslationsResponse {
}

message CheckForNewTranslationsForAllClientsRequest {
}

message CheckForNewTranslationsForAllClientsResponse {
}

// The greyhound message that is produced when some content is translated in some locale
message ContentTranslatedEvent {
    option (wix.api.entity) = {
      fqdn: "wix.localization.translator.v1.event"
      segment: USERS
    };
    // The unique content uri provided during the upload flow
    string content_uri = 1;

    // Language that the content was translated at (Smarting locale format)
    string locale = 2;

    // Configuration that defines a client
    ClientConfig config = 3;

    // True if all of the text within that content had been fully localized; False if only partially
    bool is_fully_localized = 4;
}
