syntax = "proto3";

package com.wixpress.appservice.api;

import "wix/api/validations.proto";
import "google/protobuf/wrappers.proto";
import "google/protobuf/timestamp.proto";
import "components_messages.proto";
import "wix/api/annotations.proto";
import "webhooks_messages.proto";
import "permissions_messages.proto";
import "listingInfo_messages.proto";
import "marketListing_messages.proto";
import "translations_data_messages.proto";
import "companies_messages.proto";
import "pricing_model/pricing_model_messages.proto";
import "wix/api/entity.proto";

option java_package = "com.wixpress.appservice.api";

message UpdatePublishKVRequest {
    repeated string ids = 1; // webSolutions ids
}

message GetLatestMarketVersionsRequest {
    repeated string ids = 1;
    google.protobuf.StringValue language_code = 2;
    bool withComponents = 4;
    // include apps that are hidden from managed apps in the response.
    bool with_hidden_from_managed_apps = 5;
}

message GetMarketVersionsRequest {
    string ids_or_slugs = 1;
    google.protobuf.StringValue language_code = 2;
    repeated VersionStatus status = 3;
}

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

message RenameAppSlugRequest {
    string app_slug = 1;
    string rename_to = 2;
    google.protobuf.StringValue app_id = 3 [(wix.api.format) = GUID];
}

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

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

message IsAppSlugExistResponse {
    bool app_slug_exist = 1;
}

message MarketVersionByAppIdsOrSlugsResponse {
    repeated MarketVersion appsVersions = 1;
}

message MarketVersion {
    string app_id = 1[(wix.api.format) = GUID];
    string version = 2;
    MarketListing market_listing = 3;
    pricing.PricingModel pricing_model = 4;
    Company company = 5;
    OpenConsentIn open_consent_in = 6;
    repeated Component components = 7;
    string slug = 8;
    google.protobuf.StringValue published_version = 9;
    UninstallActions uninstall_action = 10; // Whether uninstalling should be blocked until further actions are taken
    bool silent_consent = 11; // should open consent and show permissions
    repeated string support_emails = 12 [(wix.api.format) = EMAIL];
    google.protobuf.Timestamp first_published_date = 13;
    Classification classification = 14; // the app's classification
}

message GetMarketVersionsByAppIdsOrSlugsRequest{
    repeated string ids_or_slugs = 1;
    google.protobuf.StringValue language_code = 2;
    bool with_components = 3;
    google.protobuf.BoolValue in_review = 4;
    google.protobuf.BoolValue with_hidden_managed_apps = 5;
}

message GetMarketVersionsByAppIdsAndVersionRequest{
    map<string, google.protobuf.StringValue> appId_to_version = 1; //map from appId to version
    google.protobuf.StringValue language_code = 2;
    bool with_components = 3;
    bool with_hidden_managed_apps = 4;
}

message GetVersionsByStatusResponse {
    repeated VersionsResponse apps = 1; //versions of this app with the given version on this page
    google.protobuf.Int32Value total = 2; //total number of versions with this status
}

message GetVersionsByStatusRequest {
    repeated VersionStatus status = 1; //the requested status
    google.protobuf.Int32Value page = 2 [(.wix.api.min) = 0]; //the desired results page
    google.protobuf.Int32Value limit = 3 [(.wix.api.max) = 100]; //the maximum amount of entries per page
    google.protobuf.StringValue signature = 4; //internal signing method - contact us for details
}

message GetLatestDisplayVersionsResponse {
    repeated DisplayVersions display_versions = 1; //all display versions for this app
}

message DisplayVersions {
    string version = 1 [(wix.api.readOnly) = true]; //the internal version id, e.g. '0.0.2'
    VersionStatus status = 2; //the status of this version
    google.protobuf.StringValue display_name = 3; //the name of this version which is displayed in the dev center, e.g. 'v1'
    repeated StatusUpdateInfo status_updates_info = 4;
    google.protobuf.Timestamp date_updated = 5; //the date this version was last updated
    google.protobuf.Timestamp date_created = 6; //the date this version was created
}

message GetLatestDisplayVersionsRequest {
    string app_id = 1 [(wix.api.format) = GUID]; //the id of the requested display versions
}

message StatusUpdateInfo {
    VersionStatus status = 1;//the status that this version of the app was updated to
    google.protobuf.Timestamp date_updated = 2;//date of update
    google.protobuf.StringValue comment = 3;//the comment that accompanied the update
    string triggered_by = 4 [(wix.api.format) = GUID];//the wix user ID of the person who update
    VersionSubmission submission = 5; //only relevant if the new status is SUBMITTED
}

message VersionsResponse {
    option (.wix.api.entity) = {
        fqdn: "wix.devcenter.versions.v1.versions_response"
        segment: USERS
    };
    string app_id = 1 [(wix.api.readOnly) = true, (wix.api.format) = GUID];
    string version = 2 [(wix.api.readOnly) = true];
    VersionStatus status = 3;
    google.protobuf.Timestamp date_created = 4;
    google.protobuf.Timestamp date_updated = 5;
    VersionType versionType = 6 [(wix.api.readOnly) = true];
    repeated StatusUpdateInfo status_updates = 7;
    google.protobuf.StringValue display_name = 8; // the version name in the market.
    AppListing app_listing = 9; // all marketing materials for this version
    google.protobuf.StringValue release_notes = 10; // the version release notes
}

message GetVersionsByAppResponse {
    repeated VersionsResponse versions = 1; // list of versions
    google.protobuf.Int32Value total = 2; // total number of versions for this app
}

message GetVersionsByAppRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    google.protobuf.Int32Value page = 2;
    google.protobuf.Int32Value limit = 3;
    google.protobuf.StringValue signature = 4; //internal signing method - contact us for details
}

message PatchedAppVersion {
    repeated Component component = 1; //Component to update
}

message PatchPreviousVersionRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    string base_version = 2 [(wix.api.readOnly) = true];
    VersionType version_type = 3 [(wix.api.readOnly) = true];
    google.protobuf.StringValue release_notes = 4;
    PatchedAppVersion patched_app_version = 5;
}

message PatchPreviousVersionResponse {
    string app_id = 1 [(wix.api.format) = GUID];
    string new_version = 2 [(wix.api.readOnly) = true];
}

// Create a new version for the app
message CreateVersionRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    VersionType version_type = 2 [(wix.api.readOnly) = true]; // todo: add length or validation
    google.protobuf.StringValue release_notes = 3;
}

message CreateVersionResponse {
    string new_version = 2 [(wix.api.readOnly) = true]; // The version that was just created
    VersionType type = 1 [(wix.api.readOnly) = true]; // The version type that was just created
}

message CreateVersionWithOnlyDevCenterDataUpdateRequest {
    // app id of the app we want to create a new version for
    string app_id = 1 [(wix.api.format) = GUID];
    // what type of major we want to create
    VersionType version_type = 2 [(wix.api.readOnly) = true];
    // release notes for this version
    google.protobuf.StringValue release_notes = 3 [(.wix.api.maxLength) = 250]; // Version notes
    // major version to work on. If we want to create a new major version, this field will have the current major version, not the one we want to create
    int32 major_version = 4;
}

message CreateVersionWithOnlyDevCenterDataUpdateResponse {
    // The version that was just created
    string new_version = 2 [(wix.api.readOnly) = true, (wix.api.maxLength) = 255]; // The version that was just created
    // The version type that was just created
    VersionType type = 1 [(wix.api.readOnly) = true]; // The version type that was just created
    // The current "best" (production) status of the app
    VersionStatus current_production_status = 3;
}

/*
If a version is XX.YY.ZZ then
XX = MAJOR
YY = MINOR
ZZ = BUILD
*/
enum VersionType {
    BUILD = 0;
    MINOR = 1;
    MAJOR = 2;
}

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

//for documentation purposes only
message AppLatestVersionMessage {
    AppLatestVersionMessageKey key = 1;
    AppLatestVersionMessageValue value = 2;
}

message AppLatestVersionMessageValue {
    string latest_version = 1;
}

message UpdateVersionRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    google.protobuf.StringValue version = 2 [(wix.api.readOnly) = true]; //the version id
    google.protobuf.StringValue comments = 3; //comments about this version update status
    VersionStatus status = 4; //the status to update this version to
    google.protobuf.StringValue release_notes = 5; //release notes about this version
    string triggered_by = 6 [(wix.api.format) = GUID]; //the WIX GUID of the person updating this version
    google.protobuf.StringValue signature = 7; //signature required for this action
    VersionSubmission submission = 8; //fields relevant only if this update is to a submitted state
    PartialVersionOptions partial_version_options = 9; // If defined, only a partial snapshot of the app draft was used
}

message VersionSubmission {
    google.protobuf.StringValue permissions_reason = 1  [(wix.api.maxLength) = 200]; // relevant if the dev added a permission other than MANAGE_INSTANCE
    repeated string screenshots = 2 [(wix.api.format) = WEB_URL]; // screenshots of the ready app for AMs to go over
    bool read_guidelines = 3; // user in DC confirmed that they have read the guidelines
}

message UpdateVersionResponse {
    string version = 1 [(wix.api.readOnly) = true]; //the version id
    VersionStatus status = 2;
}

enum VersionStatus {
    NONE_STATUS = 0;//default, internal use status. do not use
    DRAFT = 1;//a version which was created in the dev center and has not started the approval process yet
    SUBMITTED = 2;//the version was submitted for review by the developer
    IN_REVIEW = 3;//the version is being reviewed by the app market team in cactus
    APPROVED = 4;//our team approved the version
    PUBLISHED = 5;//this version is published - only one version can be published at any given time; if this app was already published, the previously published version's status is now ARCHIVED
    DECLINED = 6;//our team did not accept this version of the app
    ARCHIVED = 7;//the status for versions that are no longer relevant
    HIDDEN = 8;//status for versions with no significant changes, e.g. for test app. for questions contact our team
    RELEASED = 9;//mark apps as RELEASED, without adding to the apps cache, and allow users to install
}

//payload for kafka event for this version on publish/unpublish
message AppVersionPublishState {
    string app_id = 1 [(wix.api.format) = GUID];
    string version = 2 [(wix.api.readOnly) = true];
    VersionStatus status = 3;
}

//payload for kafka event for this version on app submit
message AppVersionStateChanged {
    string app_id = 1 [(wix.api.format) = GUID];
    string version = 2 [(wix.api.readOnly) = true];
    oneof state {
        AppVersionCreated created = 3;
        AppVersionSubmitted submitted = 4;
        AppVersionPublished published = 5;
        AppVersionDeclined declined = 6;
        AppVersionReleased released = 7;
        AppVersionApproved approved = 8;
        AppVersionDraftChanged draftChanged = 9;
        AppVersionArchived archived = 10;
    }

    message AppVersionCreated {}
    message AppVersionSubmitted {}
    message AppVersionPublished {}
    message AppVersionDeclined {}
    message AppVersionReleased {}
    message AppVersionApproved {}
    message AppVersionDraftChanged {}
    message AppVersionArchived {}

    VersionStatus previous_state = 11;
    PartialVersionOptions partial_version_options = 12 [(.wix.api.field_maturity) = ALPHA, (.wix.api.field_exposure) = PRIVATE]; // If defined, only a partial snapshot of the app draft was updated
}

message SubmitAppRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    bool publish_immediately = 2; // Whether or not the app should not only be submitted, but published immediately. Only relevant to apps that are already published to the app market and the person who triggered it is a wix employee
    //    bool force_major = 3; // Jah is one, wallah kulu min Allah. Whether or not we are forcing this submission to update the MAJOR number of the version (which essentially means no silent updates)
    VersionSubmission submission = 4; // fields relevant only if this update is to a submitted state
    VersionStatus final_status = 5; // Either APPROVED/PUBLISHED will be allowed, anything else will be ignored.
    google.protobuf.StringValue triggered_by = 6 [(wix.api.format) = GUID]; //the WIX GUID of the person updating this version
    google.protobuf.StringValue comments = 7; //comments about this version update status
    PartialVersionOptions partial_version_options = 8; // If defined, only a partial snapshot of the app draft will be used
}

message PartialVersionOptions {
    bool include_draft_dev_center_data = 1; // Include dev center draft changes in the submitted data
    bool include_draft_market_listing_data = 2; // Include market listing draft data in the submitted data
    bool include_draft_pricing_info_data = 3; // Include pricing info draft data in the submitted data
}

message SubmitAppResponse {
    string version = 1; // Created version by this submission
    VersionStatus status = 2; // Current status this version is in
    //    google.protobuf.BoolValue bumped_major = 3; // whether or not major was bumped
}

message ReleaseAppRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    google.protobuf.StringValue version = 2; // Version to release.
}

message CalculateVersionTypeRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    string version = 2; // Version to find diff from
}

message CanTeamUpdateVersionStatusRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    string version = 2  [(wix.api.minLength) = 0, (wix.api.maxLength) = 30]; // Version to find diff from
}

message CanTeamUpdateVersionStatusResponse {
    //TBD RETURN ARRAY OF REASONS THAT BLOCKS THE USER FROM APPROVING
    bool can_update = 1;
}

message CalculateVersionTypeResponse {
    VersionType version_type = 1;
}

message ReleaseAppResponse {
    string version = 1; // Current version by this release.
    VersionStatus status = 2; // Current status this version is in.
}

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

message CreateNewDraftResponse {}

enum Classification {
    SITE_APP = 0; // A Regular app entity - used to installed on sites.
    API_KEY = 1; // represents an account API KEY to access wix services.
    VELO_APP = 2; // represents an app developed for Velo editor.
    PRIVATE_APP = 3; // Private App that should be available only for the owner account / sub-accounts.
    HEADLESS = 4; //represents an External Headless (3rd party) App that has access to Wix Public Services
    FUNCTION_ACTIVATION_APP = 5; // represents an app specific to a Meta Site that stores data about Activated Functions in that Meta Site
}

message AppSlugChanged {
    string app_id = 1 [(wix.api.format) = GUID]; // app id of the app with the changed slug
    string slug = 2 [(.wix.api.minLength) = 1, (wix.api.maxLength) = 200]; // The slug of the app. A human readable identifier of the app
}

message GetLatestProductionVersionRequest {
    string app_id = 1 [(wix.api.format) = GUID]; // App ID
}

message GetLatestProductionVersionResponse {
    google.protobuf.StringValue version = 1 [(wix.api.maxLength) = 30]; // Latest production version
}
