// flynt-disable disallow-direct-common-imports, field-lower-snake-case, missing-deprecated-field-annotation, missing-string-validations, deprecated-callback-event-validation

syntax = "proto3";

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

import "google/protobuf/timestamp.proto";
import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";
import "wix/api/annotations.proto";
import "google/protobuf/empty.proto";
import "wix/api/callback.proto";
import "wix/api/entity.proto";
import "wix/api/permissions.proto";
import "wix/api/validations.proto";
import "wix/api/subscription.proto";
import "wix/common/query.proto";
import "wix/common/paging.proto";
import "wix/common/domainevents/domainevents.proto";
import "wix/http/field_mask.proto";
import "wix/devcenter/apps/versions/v1/app_version.proto";
import "google/protobuf/wrappers.proto";
import "apps_messages.proto";
import "versions_messages.proto";
import "pricing_model/pricing_model_messages.proto";


/**
  Manages AppVersions
 */
service AppVersionsService {
    option (.wix.api.service_maturity) = GA;
    option (.wix.api.service_exposure) = PUBLIC;
    option (.wix.api.service_entity).message = "wix.devcenter.apps.versions.v1.AppVersion";

    /**
      Creates a new AppVersion
     */
    //flynt-disable http-mapping-breaking-change
    rpc CreateAppVersion (CreateAppVersionRequest) returns (CreateAppVersionResponse) {
        option (wix.api.exposure) = PRIVATE;
        option (.wix.api.permission) = {
            name: "DEV_CENTER.CREATE_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.MANAGE_APPS"
            type: MANUAL
        };
        option (.wix.api.required) = "CreateAppVersionRequest.app_version";
        option (.wix.api.callback) = {
            event_type: CREATED
        };
        option (.wix.api.crud) = {
            method: CREATE
            create_options: {
                item_field: "app_version"
            }
        };
    }

    /**
      Creates a new major version
     */
    //flynt-disable http-mapping-breaking-change
    rpc CreateNewMajorVersion (CreateNewMajorVersionRequest) returns (CreateNewMajorVersionResponse) {
        option (wix.api.exposure) = INTERNAL;
        option (.wix.api.permission) = {
            name: "DEV_CENTER.WRITE_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.MANAGE_APPS"
            type: MANUAL
        };
        option (.wix.api.required) = "CreateNewMajorVersionRequest.app_id";
        option (.wix.api.callback) = {
            event_type: CREATED
        };
    }

    /**
        Check If Version Bump Required
    */
    rpc CheckIfVersionBumpRequired (CheckIfVersionBumpRequiredRequest) returns (CheckIfVersionBumpRequiredResponse) {
        option (google.api.http).get = "/v1/app-versions/version-bump-check";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.READ_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.READ_APPS"
            type: MANUAL
        };
        option (.wix.api.required) = "CheckIfVersionBumpRequiredRequest.app_id";
    }

    /**
    Suggest new versions
     */
    rpc SuggestNextVersions (SuggestNextVersionsRequest) returns (SuggestNextVersionsResponse) {
        option (.wix.api.maturity) = BETA;
        option (google.api.http).get = "/v1/app-versions/suggest-next-versions";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.READ_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.READ_APPS"
            type: MANUAL
        };
        option (.wix.api.required) = "SuggestNextVersionsRequest.app_id";
    }

    /**
      Creates a new major version and lock it immediately
     */
    //flynt-disable http-mapping-breaking-change
    rpc CreateNewMajorVersionAndLock (CreateNewMajorVersionAndLockRequest) returns (CreateNewMajorVersionAndLockResponse) {
        option (wix.api.exposure) = INTERNAL;
        option (.wix.api.permission) = {
            name: "DEV_CENTER.WRITE_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.GLOBAL_VERSION_STATE_CHANGE"
            type: MANUAL
        };
        option (.wix.api.required) = "CreateNewMajorVersionAndLockRequest.app_id";
        option (.wix.api.callback) = {
            event_type: CREATED
        };
    }

    /**
      Get a AppVersion by id, version and state
     */
    //flynt-disable http-mapping-breaking-change
    rpc GetAppVersion (GetAppVersionRequest) returns (GetAppVersionResponse) {
        option (wix.api.exposure) = INTERNAL;
        option (.wix.api.permission) = {
            name: "DEV_CENTER.READ_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.READ_APPS"
            type: MANUAL
        };
        option (.wix.api.required) = "GetAppVersionRequest.app_id";
    }

    /**
    Get the latest draft (draft of the latest version of the app) enriched with permissions, components, dependencies
     */
    //flynt-disable http-mapping-breaking-change
    rpc GetLatestDraft (GetLatestDraftRequest) returns (GetLatestDraftResponse) {
        option (wix.api.exposure) = INTERNAL;
        option (.wix.api.permission) = {
            name: "DEV_CENTER.READ_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.READ_APPS"
            type: MANUAL
        };
        option (.wix.api.required) = "GetLatestDraftRequest.app_id";
    }

    /**
    Get the latest draft (draft of the latest version of the app) without enrichment
     */
    rpc GetLatestDraftVersion (GetLatestDraftVersionRequest) returns (GetLatestDraftVersionResponse) {
        option (wix.api.exposure) = INTERNAL;
        option (.wix.api.permission) = {
            name: "DEV_CENTER.READ_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.READ_APPS"
            type: MANUAL
        };
        option (.wix.api.required) = "GetLatestDraftVersionRequest.app_id";
    }

    /**
        Get latest production version
     */
    rpc GetLatestProductionVersion (GetLatestProductionVersionRequest) returns (GetLatestProductionVersionResponse) {
        option (google.api.http).get = "/v1/app-versions/get-latest-production";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.READ_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.READ_APPS"
            type: MANUAL
        };
        option (.wix.api.required) = "GetLatestProductionVersionRequest.app_id";
    }

    /**
        Get latest production versions
     */
    rpc ListLatestProductionVersions (ListLatestProductionVersionsRequest) returns (ListLatestProductionVersionsResponse) {
        option (google.api.http).get = "/v1/app-versions/get-latest-production-for-apps";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.READ_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.READ_APPS"
            type: MANUAL
        };
    }

    /**
      Update a AppVersion, supports partial update
      Pass the latest `revision` for a successful update
     */
    //flynt-disable http-mapping-breaking-change
    rpc UpdateAppVersion (UpdateAppVersionRequest) returns (UpdateAppVersionResponse) {
        option (wix.api.exposure) = INTERNAL;
        option (.wix.api.permission) = {
            name: "DEV_CENTER.WRITE_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.MANAGE_APPS"
            type: MANUAL
        };
        option (.wix.api.required) = "UpdateAppVersionRequest.app_version";
        option (.wix.api.required) = "UpdateAppVersionRequest.app_version.id";
        option (.wix.api.required) = "UpdateAppVersionRequest.app_version.revision";
        option (.wix.api.callback) = {
            event_type: UPDATED
        };
        option (wix.http.infer_fieldmask) = {
            from: "app_version"
            fieldmask: "mask"
        };
        option (.wix.api.crud) = {
            method: UPDATE
            update_options: {
                item_field: "app_version"
            }
        };
    }

    /**
    Triggers latest app version event for migration
     */
    rpc TriggerLatestProductionAppVersion (TriggerLatestProductionAppVersionRequest) returns (TriggerLatestProductionAppVersionResponse) {
        option (wix.api.exposure) = PRIVATE;
        option (.wix.api.permission) = {
            name: "DEV_CENTER.WRITE_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.MANAGE_APPS"
            type: MANUAL
        };
        option (.wix.api.callback) = {
            event_type: UPDATED
        };
    }

    /**
  Triggers app version event for migration
 */
    rpc TriggerProductionAppVersion (TriggerProductionAppVersionRequest) returns (TriggerProductionAppVersionResponse) {
        option (wix.api.exposure) = PRIVATE;
        option (.wix.api.permission) = {
            name: "DEV_CENTER.WRITE_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.MANAGE_APPS"
            type: MANUAL
        };
        option (.wix.api.callback) = {
            event_type: UPDATED
        };
    }

    /**
        Lock a draft of a specific app version
     */
    //flynt-disable http-mapping-breaking-change
    rpc LockAppVersionDraft (LockAppVersionDraftRequest) returns (LockAppVersionDraftResponse) {
        option (wix.api.exposure) = INTERNAL;
        option (.wix.api.required) = "LockAppVersionDraftRequest.app_id";
        option (.wix.api.required) = "LockAppVersionDraftRequest.version";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.WRITE_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.GLOBAL_VERSION_STATE_CHANGE"
            type: MANUAL
        };
    }

    /*
    Promotes the locked draft a the given version to production state
     */
    //flynt-disable http-mapping-breaking-change
    rpc PromoteAppVersionToProduction (PromoteAppVersionToProductionRequest) returns (PromoteAppVersionToProductionResponse) {
        option (wix.api.exposure) = INTERNAL;
        option (.wix.api.required) = "PromoteAppVersionToProductionRequest.app_id";
        option (.wix.api.required) = "PromoteAppVersionToProductionRequest.version";
        option (.wix.api.required) = "PromoteAppVersionToProductionRequest.revision";
        option (.wix.api.permission).name = "DEV_CENTER.GLOBAL_VERSION_STATE_CHANGE";
    }

    /*
    Promotes the unlocked draft of a given version to production state
     */
    // flynt-disable required-annotation-breaking-change
    rpc PromoteAppVersionFromDraftToProduction (PromoteAppVersionFromDraftToProductionRequest) returns (PromoteAppVersionFromDraftToProductionResponse) {
        option (.wix.api.maturity) = BETA;
        option (google.api.http).post = "/v1/app-versions/promote-from-draft";
        option (.wix.api.required) = "PromoteAppVersionFromDraftToProductionRequest.app_id";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.WRITE_APP_VERSION"
            type: MANUAL
        };
    }

    /**
        Lock a draft of a specific app version
     */
    //flynt-disable http-mapping-breaking-change
    rpc UnlockAppVersionDraft (UnlockAppVersionDraftRequest) returns (UnlockAppVersionDraftResponse) {
        option (wix.api.exposure) = INTERNAL;
        option (.wix.api.required) = "UnlockAppVersionDraftRequest.app_id";
        option (.wix.api.required) = "UnlockAppVersionDraftRequest.version";
        option (.wix.api.required) = "UnlockAppVersionDraftRequest.revision";
        option (.wix.api.permission).name = "DEV_CENTER.GLOBAL_VERSION_STATE_CHANGE";
    }

    /**
    List notes of an app
     */
    rpc ListNotes (ListNotesRequest) returns (ListNotesResponse) {
        option (google.api.http).get = "/v1/app-versions/notes";
        option (.wix.api.required) = "ListNotesRequest.app_id";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.READ_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.READ_APPS"
            type: MANUAL
        };
    }

    /**
      Delete a AppVersion
     */
    //flynt-disable http-mapping-breaking-change
    rpc DeleteAppVersion (DeleteAppVersionRequest) returns (DeleteAppVersionResponse) {
        option (wix.api.exposure) = PRIVATE;
        option (.wix.api.permission).name = "DEV_CENTER.DELETE_APP_VERSION";
        option (.wix.api.required) = "DeleteAppVersionRequest.app_id";
        option (.wix.api.required) = "DeleteAppVersionRequest.version";
        option (.wix.api.required) = "DeleteAppVersionRequest.state";
        option (.wix.api.callback) = {
            event_type: DELETED
        };
    }

    /**
      Query AppVersions using [WQL - Wix Query Language](https://dev.wix.com/api/rest/getting-started/api-query-language)
     */
    rpc QueryAppVersion (QueryAppVersionRequest) returns (QueryAppVersionResponse) {
        option (google.api.http).post = "/v1/app-versions/query";
        option (.wix.api.required) = "QueryAppVersionRequest.query";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.READ_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.READ_APPS"
            type: MANUAL
        };
        option (.wix.api.crud) = {
            method: QUERY
            query_options: {
                paging {
                    type: CURSOR
                    paging_metadata_field: "paging_metadata" // in response object
                }
                query_field: "query"
                items_field: "app_versions"
                wql: {
                    pattern: {
                        operator: ALL_APPLICABLE_OPERATORS // will be smart - allow by type
                        field: "id"
                        field: "version"
                        field: "state"
                        field: "metadata.account_id"
                        sort: NONE // NONE|ASC|DESC|BOTH. NONE is the default.
                        required_fields: {
                            required_field: {
                                path: "id"
                            }
                        }
                    }
                }
            };
        };
    }

    /*
    Used for migration, will be deleted.
    In case the App Version already exists, it will be updated.
     */
    rpc CreateAppVersionForMigration (CreateAppVersionForMigrationRequest) returns (CreateAppVersionForMigrationResponse) {
        option (.wix.api.required) = "CreateAppVersionForMigrationRequest.app_version";
        option (.wix.api.callback) = {
            event_type: CREATED
        };
        option (.wix.api.exposure) = PRIVATE;
    }


    /*
    Used for migration, will be deleted.
     */
    rpc CreateDraftIfNeeded (CreateDraftIfNeededRequest) returns (CreateDraftIfNeededResponse) {
        option (.wix.api.callback) = {
            event_type: CREATED
        };
        option (.wix.api.exposure) = PRIVATE;
    }

    /*
    Used for migration, will be deleted.
     */
    rpc CreateFullVersionForMigration (CreateFullVersionForMigrationRequest) returns (CreateFullVersionForMigrationResponse) {
        option (.wix.api.callback) = {
            event_type: CREATED
        };
        option (.wix.api.exposure) = PRIVATE;
    }

    /*
    Fixes permissions in the permissions cache (all-in-mem)
     */
    rpc FixPermissionStore (FixPermissionStoreRequest) returns (FixPermissionStoreResponse) {
        option (.wix.api.exposure) = PRIVATE;
    }

    /**
  Consume AppVersion DomainEvents in order to create full versions
 */
    rpc ConsumeAppVersionsDomainEvents (wix.common.domainevents.DomainEvent) returns (google.protobuf.Empty) {
        option (wix.api.exposure) = PRIVATE;
        option (wix.api.subscription) = {
            entity: "wix.devcenter.apps.versions.v1.AppVersion",
        };
    }

    /*
    Consume app domain events
     */
    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",
        };
    }

    /*
    Consume app version state change event (app market events)
     */
    rpc ConsumeAppVersionStateChanged (com.wixpress.appservice.api.AppVersionStateChanged) returns (google.protobuf.Empty) {
        option (wix.api.subscription) = {
            topic: "app-version-state-changed"
        };
    }

    /*
    Consume components domain events
     */
    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",
        };
    }

    /*
   Consume components domain events
    */
    rpc ConsumeAppDependenciesDomainEvents (wix.common.domainevents.DomainEvent) returns (google.protobuf.Empty) {
        option (wix.api.exposure) = PRIVATE;
        option (wix.api.subscription) = {
            entity: "wix.devcenter.apps.dependencies.v2.AppDependency",
        };
    }

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

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

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

    /**
        Get highest full version for given apps
    */
    //flynt-disable http-mapping-breaking-change
    rpc ListLatestProductionAppVersionsOfAccount (ListLatestProductionAppVersionsOfAccountRequest) returns (ListLatestProductionAppVersionsOfAccountResponse) {
        option (wix.api.exposure) = INTERNAL;
        option (.wix.api.permission) = {
            name: "DEV_CENTER.READ_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.READ_APPS"
            type: MANUAL
        };
    }

    option (wix.api.event) = {
        topic: "app-draft-changed-delayed"
        segment: USERS
        payload: "wix.devcenter.apps.versions.v1.AppDraftChangedEvent"
    };

    /**
     Consume PricingModelChanged Events in order to populate the Pricing Model Cache
    */
    rpc ConsumePricingModelChangedEvent (com.wixpress.appservice.api.pricing.PricingModelChangedEvent) returns (google.protobuf.Empty) {
        option (wix.api.exposure) = PRIVATE;
        option (wix.api.subscription) = {
            topic: "app-market-pricing-model-changed"
            segment: USERS
        };
    }

    /**
     Consume Plan DomainEvents in order to populate the Pricing Model Cache
    */
    rpc ConsumePlanDomainEvent(wix.common.domainevents.DomainEvent) returns (google.protobuf.Empty) {
        option (.wix.api.exposure) = PRIVATE;
        option (.wix.api.subscription) = {
            entity: "wix.devcenter.plans.v1.Plan"
        };
    }

    /**
      Add component to application
     */
    rpc AddComponentToApplication (AddComponentToApplicationRequest) returns (AddComponentToApplicationResponse) {
        option (.wix.api.exposure) = PRIVATE;
        option (.wix.api.permission) = {
            name: "DEV_CENTER.WRITE_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.MANAGE_APPS"
            type: MANUAL
        };
        option (.wix.api.callback) = {
            event_type: UPDATED
        };
        option (.wix.api.required) = "AddComponentToApplicationRequest.app_id";
        option (.wix.api.required) = "AddComponentToApplicationRequest.version";
        option (.wix.api.required) = "AddComponentToApplicationRequest.state";
        option (.wix.api.required) = "AddComponentToApplicationRequest.component";
    }

    /**
      Remove component from application
     */
    rpc RemoveComponentFromApplication (RemoveComponentFromApplicationRequest) returns (RemoveComponentFromApplicationResponse) {
        option (.wix.api.exposure) = PRIVATE;
        option (.wix.api.permission) = {
            name: "DEV_CENTER.WRITE_APP_VERSION"
            type: MANUAL
        };
        option (.wix.api.additional_permission) = {
            name: "DEV_CENTER.MANAGE_APPS"
            type: MANUAL
        };
        option (.wix.api.callback) = {
            event_type: UPDATED
        };
        option (.wix.api.required) = "RemoveComponentFromApplicationRequest.app_id";
        option (.wix.api.required) = "RemoveComponentFromApplicationRequest.version";
        option (.wix.api.required) = "RemoveComponentFromApplicationRequest.state";
        option (.wix.api.required) = "RemoveComponentFromApplicationRequest.component_id";
    }
}

message CreateAppVersionRequest {
    AppVersion app_version = 1; // AppVersion to be created
}

message CreateAppVersionResponse {
    AppVersion app_version = 1; // The created AppVersion
}

message CreateNewMajorVersionRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // app id to create a new version to
}

message CreateNewMajorVersionResponse {
    AppVersion app_version = 1; // The created AppVersion
}

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

message CheckIfVersionBumpRequiredResponse {
    bool bump_needed = 1;
}

message SuggestNextVersionsRequest {
    // app id to suggest next versions for
    string app_id = 1 [(.wix.api.format) = GUID];
}

message SuggestNextVersionsResponse {
    // The suggested next minor version. Will be None if the app must be bumped to a new major version
    google.protobuf.StringValue next_minor = 1 [(.wix.api.maxLength) = 250];
    // The suggested next major version
    string next_major = 2 [(.wix.api.maxLength) = 250];
}

message CreateNewMajorVersionAndLockRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // app id to create a new version to
    google.protobuf.StringValue notes = 4 [(.wix.api.maxLength) = 250]; // Version notes
    CreatedBy created_by = 2; // The entity which created the new major version
}

message CreatedBy {
    enum CreatedByType  {
        UNKNOWN_CREATED_BY = 0;
        USER = 1;
        SERVICE = 2;
        ACCOUNT = 3;
    }
    CreatedByType type = 1; // The type of the created by entity
    oneof created_by_options {
        option (wix.api.aligned_with_enum) = {
            field: "type",
            suffix: "id"
        };
        string user_id = 2 [(.wix.api.format) = GUID]; // User id of the version creator
        string service_id = 3 [(.wix.api.format) = GUID]; // service id of the version creator
        string account_id = 4 [(.wix.api.format) = GUID]; // account id of the version creator
    }
}

message CreateNewMajorVersionAndLockResponse {
    AppVersion app_version = 1; // The created (and locked) AppVersion
}

message CreateAppVersionForMigrationRequest {
    AppVersion app_version = 1; // AppVersion to be created
}

message CreateAppVersionForMigrationResponse {
    AppVersion app_version = 1; // The created AppVersion
}

message CreateDraftIfNeededRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // app id
    int32 version = 2; // version
}

message CreateDraftIfNeededResponse {
    AppVersion app_version = 1; // The created AppVersion
}

message TriggerProductionAppVersionRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // app id
    int32 version = 2; // version
}

message TriggerProductionAppVersionResponse {}

message CreateFullVersionForMigrationRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // app id
    int32 major = 2; // major version
    int32 minor = 3; // minor version
    int32 build = 4; // build version
    google.protobuf.StringValue note = 5; // version notes
}

message CreateFullVersionForMigrationResponse {

}

message GetAppVersionRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // Id of the AppVersion to retrieve
    int32 version = 2; // Version of the app that is requested
    State state = 3; //indicates if this is the draft instance of the version.
    bool consistent = 4; // If response should be eventually consistent
}

message GetAppVersionResponse {
    AppVersion app_version = 1; // The retrieved AppVersion
}

message GetLatestDraftRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // Id of the AppVersion to retrieve
    bool consistent = 2; // Retrieves consistent data
}

message GetLatestDraftResponse {
    AppVersion app_version = 1; // The retrieved AppVersion
}

message GetLatestDraftVersionRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // Id of the AppVersion to retrieve
    bool consistent = 2; // Retrieves consistent data
}

message GetLatestDraftVersionResponse {
    AppVersion app_version = 1; // The retrieved AppVersion
}

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

message GetLatestProductionVersionResponse {
    AppVersion app_version = 1; // The retrieved AppVersion
}

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

message ListLatestProductionVersionsResponse {
    repeated AppVersion app_versions = 1 [(wix.api.maxSize) = 100];
}

message UpdateAppVersionRequest {
    AppVersion app_version = 1; // AppVersion to be updated, may be partial
    google.protobuf.FieldMask mask = 2; // Explicit list of fields to update
}

message UpdateAppVersionResponse {
    AppVersion app_version = 1; // The updated AppVersion
}

message DeleteAppVersionRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // Id of the AppVersion to delete
    int32 version = 2; // Version of the app to delete
    State state = 3; // State of the app to delete
}

message DeleteAppVersionResponse {
}

message QueryAppVersionRequest {
    .wix.common.QueryV2 query = 1; // WQL expression
}

message QueryAppVersionResponse {
    repeated AppVersion app_versions = 1; // The retrieved AppVersions
    wix.common.CursorPagingMetadata paging_metadata = 2; // Paging
}

message LockAppVersionDraftRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // Id of the AppVersion to retrieve
    google.protobuf.Int32Value version = 2; // Version of the app that is requested
    google.protobuf.Int64Value revision = 3; // Revision of the draft we want to lock (ignored if its the max version of the app)
    google.protobuf.StringValue notes = 4 [(.wix.api.maxLength) = 250]; // Version notes
    bool always_use_db = 5; // Always use the draft record of a app version from the database, don't re-calculate it for highest major version
    CreatedBy created_by = 6; // The entity which created the version
}

message LockAppVersionDraftResponse {
    AppVersion app_version = 1; // The retrieved AppVersion
}

message UnlockAppVersionDraftRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // Id of the AppVersion to unlock
    google.protobuf.Int32Value version = 2; // Version of the app
    google.protobuf.Int64Value revision = 3;
}

message UnlockAppVersionDraftResponse {
    AppVersion app_version = 1; // The locked draft that got unlocked
}

message PromoteAppVersionToProductionRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // Id of the AppVersion to promote to production
    google.protobuf.Int32Value version = 2; // Version of the app
    google.protobuf.Int64Value revision = 3;
    bool shouldRelease = 4 [deprecated = true]; // Temporarily used until Submission service is ready
    bool create_new_major = 5; // Promote the locked draft to a new major version (only applicable if the current version is the highest of the app).
}

message PromoteAppVersionToProductionResponse {
    AppVersion app_version = 1; // The AppVersion that got promoted to production
}

message PromoteAppVersionFromDraftToProductionRequest {
    // Id of the AppVersion to promote to production
    string app_id = 1 [(.wix.api.format) = GUID];
    // Version of the app
    google.protobuf.Int32Value version = 2;
    // Promote the draft to a new major version (only applicable if the current version is the highest of the app).
    bool create_new_major = 3;
    // Version notes
    google.protobuf.StringValue notes = 4 [(.wix.api.maxLength) = 250];
    // The promote strategy
    PromoteStrategy promote_strategy = 5;

    enum PromoteStrategy {
        UNKNOWN_STRATEGY = 0;
        // Promote the entire app (all components)
        ENTIRE_APP = 1;
    }

}

message PromoteAppVersionFromDraftToProductionResponse {
    // The AppVersion that got promoted to production
    AppVersion app_version = 1;
}

message ListNotesRequest {
    string app_id = 1  [(.wix.api.format) = GUID]; // Id of the AppVersion the notes are requested for
    google.protobuf.Int32Value version = 2; // Version of the app. Optional, if not provided, all versions will be fetching
    wix.common.CursorPaging paging = 3; // Paging, nothing for the first request
}

message ListNotesResponse {
    repeated Note notes = 1; // version notes
    wix.common.CursorPagingMetadata paging_metadata = 2; // Paging
}

message Note {
    string fullVersion = 1; // The full version of the note
    google.protobuf.StringValue note = 2; // The release notes
    string version_name = 3 [(.wix.api.field_maturity) = ALPHA, (wix.api.readOnly) = true, (.wix.api.maxLength) = 10]; // Auto incremented version number
    // flynt-disable field-type-breaking-change
    CreatedBy created_by = 4 [(.wix.api.field_maturity) = ALPHA]; // Who created the version
    com.wixpress.appservice.api.VersionStatus app_market_version_status = 5; // The status of the version
    google.protobuf.Timestamp created_date = 6 [(.wix.api.field_maturity) = ALPHA, (wix.api.readOnly) = true]; // Represents the time this version was created
    google.protobuf.Timestamp updated_date = 7 [(.wix.api.field_maturity) = ALPHA, (wix.api.readOnly) = true]; // Represents the time version App was last updated
}

message ListLatestProductionAppVersionsOfAccountRequest {
    .wix.common.CursorPaging cursor_paging = 1; // Optional: if not provided will default to first page and limit of 100
}

message ListLatestProductionAppVersionsOfAccountResponse {
    repeated AppVersion app_versions = 1; // The AppVersion that got promoted to production
    .wix.common.Cursors cursors = 2; // Cursor for the next batch of responses
}

message TriggerLatestProductionAppVersionRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // app id
}

message TriggerLatestProductionAppVersionResponse {}

message FixPermissionStoreRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // app id
    int32 version = 2; // Version of the app to delete
    bool dry_run = 3; // When dry running, it will only detect missing entry and report to log
}

message FixPermissionStoreResponse {};

message AddComponentToApplicationRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // Application ID
    int32 version = 2; // Version of the application
    State state = 3; // State of the application
    VersionedComponent component = 4; // Component to add
}

message AddComponentToApplicationResponse {};

message RemoveComponentFromApplicationRequest {
    string app_id = 1 [(.wix.api.format) = GUID]; // Application ID
    int32 version = 2; // Version of the application
    State state = 3; // State of the application
    string component_id = 4 [(.wix.api.format) = GUID]; // Component ID
}

message RemoveComponentFromApplicationResponse {};

