syntax = "proto3";

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

import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";
import "wix/api/annotations.proto";
import "wix/api/callback.proto";
import "wix/api/entity.proto";
import "wix/api/permissions.proto";
import "wix/api/validations.proto";
import "wix/http/field_mask.proto";
import "wix/devcenter/plans/v1/upstream/wix/common/paging.proto";
import "wix/devcenter/plans/v1/upstream/wix/query/query.proto";
import "wix/devcenter/plans/v1/plan.proto";
import "wix/common/data/dataextensions/update-extended-fields-messages.proto";
import "wix/devcenter/plans/v1/feature.proto";
import "wix/devcenter/plans/v1/plan-translation.proto";
import "wix/devcenter/plans/v1/settings.proto";
import "wix/api/subscription.proto";
import "google/protobuf/empty.proto";
import "com/wixpress/vi/localization/translator/content-translation-service.proto";
import "versions_messages.proto";
import "google/protobuf/wrappers.proto";

/**
  Manages Plans
 */
service Plans {

  option (wix.api.service_maturity) = BETA;
  option (wix.api.service_exposure) = PRIVATE;
  option (wix.api.service_entity).message = "wix.devcenter.plans.v1.Plan";

  /**
    Creates a Plan.

    The request body must include lorem_uppercase and business address. Ipsum is optional.
   */
  rpc CreatePlan (CreatePlanRequest) returns (CreatePlanResponse) {
    option (google.api.http).post = "/v1/plans";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_CREATE"
      type: MANUAL
    };
    option (wix.api.required) = "CreatePlanRequest.plan";
    option (wix.api.crud) = {
      method: CREATE
      create_options: {
        item_field: "plan"
      }
    };
    option (wix.api.callback) = {
      event_type: CREATED
    };
  }

  /**
    Retrieves a Plan.
   */
  rpc GetPlan (GetPlanRequest) returns (GetPlanResponse) {
    option (google.api.http).get = "/v1/plans/{id}";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_READ"
      type: MANUAL
    };
    option (wix.api.required) = "GetPlanRequest.id";
    option (wix.api.crud) = {
      method: GET_ITEM
      get_options: {
        id_field: "id"
      }
    };
  }

  /**
  Updates a Plan draft.
  Each time the Plan is updated,
  `revision` increments by 1.
  The current `revision` must be passed when updating the Plan.
  This ensures you're working with the latest Plan
  and prevents unintended overwrites.
   */
  rpc UpdatePlanDraft (UpdatePlanDraftRequest) returns (UpdatePlanDraftResponse) {
    option (google.api.http).patch = "/v1/plans/{plan.plan_id}";
    option (wix.api.required) = "UpdatePlanDraftRequest.plan";
    option (wix.api.required) = "UpdatePlanDraftRequest.plan.plan_id";
    option (wix.api.required) = "UpdatePlanDraftRequest.plan.revision";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_UPDATE"
      type: MANUAL
    };
    option (wix.api.callback) = {
      event_type: UPDATED
    };
    option (wix.http.infer_fieldmask) = {
      from: "plan"
      fieldmask: "field_mask"
    };
    option (wix.api.crud) = {
      method: UPDATE
      update_options: {
        item_field: "plan"
        fieldmask_field: "field_mask"
      }
    };
  }

  /**
    Retrieves a list of Plans, given the provided [paging, filtering, and sorting][1].
    Up to 1,000 Plans can be returned per request.
    To learn how to query Plans, see [API Query Language][2].
    [1]: https://dev.wix.com/api/rest/getting-started/sorting-and-paging
    [2]: https://dev.wix.com/api/rest/getting-started/api-query-language
   */
  rpc QueryPlans (QueryPlansRequest) returns (QueryPlansResponse) {
    option (google.api.http).post = "/v1/plans/query";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_READ"
      type: MANUAL
    };
    option (wix.api.crud) = {
      method: QUERY
      query_options: {
        items_field: 'plans'
        wql: {
          pattern: {
            operator: ALL_APPLICABLE_OPERATORS
            field: "plan_id"
            field: "app_id"
            field: "visible_in_pages"
            field: "status"
            field: "free_trial_days"
            field: "vendor_id"
            field: "payment"
          }
        }
      }
    };
  }

  /**
  Creates a Plan.

  The request body must include lorem_uppercase and business address. Ipsum is optional.
 */
  rpc PublishPlan (PublishPlanRequest) returns (PublishPlanResponse) {
    option (google.api.http).post = "/v1/plans/{plan_id}/publish";
    option (wix.api.required) = "PublishPlanRequest.plan_id";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_UPDATE"
      type: MANUAL
    };
    option (wix.api.callback) = {
      event_type: UPDATED
    };
  }

  rpc SetExternalBilling (SetExternalBillingRequest) returns (SetExternalBillingResponse) {
    option (.wix.api.permission).name = "DEV_CENTER_UPDATE_PERMISSION";
    option (wix.api.exposure) = PRIVATE;
    option (wix.api.callback) = {
      event_type: UPDATED
    };
  }

  rpc ConsumeAppVersionStateChanged (com.wixpress.appservice.api.AppVersionStateChanged) returns (google.protobuf.Empty) {
    option (wix.api.subscription) = {
      topic: "app-version-state-changed"
    };
    option (.wix.api.callback) = {
      event_type: UPDATED
    };
  }

  rpc Compare(CompareRequest) returns (CompareResponse) {
    option (.wix.api.permission).name = "DEVCENTER.PLAN_COMPARE";
  }
}

service Features {
  option (wix.api.service_exposure) = PRIVATE;
  option (wix.api.service_entity).message = "wix.devcenter.plans.v1.Plan";

  /**
  Creates a Feature.
 */
  rpc CreateFeature (CreateFeatureRequest) returns (CreateFeatureResponse) {
    option (google.api.http).post = "/v1/features";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_UPDATE"
      type: MANUAL
    };
    option (wix.api.required) = "CreateFeatureRequest.feature";
    option (wix.api.required) = "CreateFeatureRequest.feature.app_id";
  }

  /**
Updates a Feature.
*/
  rpc UpdateFeature (UpdateFeatureRequest) returns (UpdateFeatureResponse) {
    option (google.api.http).patch = "/v1/features/{feature.id}";
    option (wix.api.required) = "UpdateFeatureRequest.feature";
    option (wix.api.required) = "UpdateFeatureRequest.feature.id";
    option (wix.api.required) = "UpdateFeatureRequest.feature.revision";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_UPDATE"
      type: MANUAL
    };
    option (wix.http.infer_fieldmask) = {
      from: "feature"
      fieldmask: "field_mask"
    };
  }

  rpc GetFeature (GetFeatureRequest) returns (GetFeatureResponse) {
    option (google.api.http).get = "/v1/features/{id}";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_READ"
      type: MANUAL
    };
    option (wix.api.required) = "GetFeatureRequest.id";
  }

  rpc DeleteFeature (DeleteFeatureRequest) returns (DeleteFeatureResponse) {
    option (google.api.http).delete = "/v1/features/{id}";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_UPDATE"
      type: MANUAL
    };
    option (wix.api.required) = "DeleteFeatureRequest.id";
  }

  rpc QueryFeatures (QueryFeaturesRequest) returns (QueryFeaturesResponse) {
    option (google.api.http).post = "/v1/features/query";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_READ"
      type: MANUAL
    };
  }

}

service PlanTranslations {
  option (wix.api.service_exposure) = PRIVATE;
  option (wix.api.service_entity).message = "wix.devcenter.plans.v1.Plan";

  rpc CreatePlanTranslation (CreatePlanTranslationRequest) returns (CreatePlanTranslationResponse) {
    option (google.api.http).post = "/v1/plans/{plan_translation.plan_id}/translations";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_UPDATE"
      type: MANUAL
    };
    option (wix.api.required) = "CreatePlanTranslationRequest.plan_translation.plan_id";
    option (wix.api.required) = "CreatePlanTranslationRequest.plan_translation.app_id";
    option (wix.api.required) = "CreatePlanTranslationRequest.plan_translation.language_code";
  }

  rpc GetPlanTranslation (GetPlanTranslationRequest) returns (GetPlanTranslationResponse) {
    option (google.api.http).get = "/v1/plans/{id}/translations";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_READ"
      type: MANUAL
    };
    option (wix.api.required) = "GetPlanTranslationRequest.id";
  }

  rpc UpdatePlanTranslation (UpdatePlanTranslationRequest) returns (UpdatePlanTranslationResponse) {
    option (google.api.http).patch = "/v1/plans/{plan_translation.id}/translations";
    option (wix.api.required) = "UpdatePlanTranslationRequest.plan_translation";
    option (wix.api.required) = "UpdatePlanTranslationRequest.plan_translation.id";
    option (wix.api.required) = "UpdatePlanTranslationRequest.plan_translation.revision";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_UPDATE"
      type: MANUAL
    };
    option (wix.http.infer_fieldmask) = {
      from: "plan_translation"
      fieldmask: "field_mask"
    };
  }

  rpc DeletePlanTranslation (DeletePlanTranslationRequest) returns (DeletePlanTranslationResponse) {
    option (google.api.http).delete = "/v1/plans/{id}/translations";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_UPDATE"
      type: MANUAL
    };
    option (.wix.api.crud) = {
      method: DELETE
      delete_options: {
        id_field: "id"
      }
    };
    option (wix.api.emits) = {
      event_type: DELETED
    };
    option (wix.api.required) = "DeletePlanTranslationRequest.id";
  }

  rpc QueryPlanTranslations (QueryPlanTranslationsRequest) returns (QueryPlanTranslationsResponse) {
    option (google.api.http).post = "/v1/plans/translations/query";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_READ"
      type: MANUAL
    };
  }

  rpc HandleContentTranslatedEvent(com.wixpress.vi.localization.translator.ContentTranslatedEvent) returns (google.protobuf.Empty) {
    option (wix.api.exposure) = PRIVATE;
    option (wix.api.subscription) = {
      topic: "translator.content-translated-event"
    };
  }
}

service PlanSettings {
  option (wix.api.service_exposure) = PRIVATE;
  option (wix.api.service_entity).message = "wix.devcenter.plans.v1.Plan";

  rpc CreateSettings (CreateSettingsRequest) returns (CreateSettingsResponse) {
    option (wix.api.permission) = {
      name: "DEV_CENTER_UPDATE_PERMISSION"
      type: MANUAL
    };
    option (wix.api.required) = "CreateSettingsRequest.settings.app_id";
  }

  rpc GetSettings (GetSettingsRequest) returns (GetSettingsResponse) {
    option (google.api.http).get = "/v1/plans/{id}/settings";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_READ"
      type: MANUAL
    };
    option (wix.api.required) = "GetSettingsRequest.id";
  }

  rpc UpdateSettings (UpdateSettingsRequest) returns (UpdateSettingsResponse) {
    option (wix.api.required) = "UpdateSettingsRequest.settings";
    option (wix.api.required) = "UpdateSettingsRequest.settings.id";
    option (wix.api.required) = "UpdateSettingsRequest.settings.revision";
    option (wix.api.permission) = {
      name: "DEV_CENTER_UPDATE_PERMISSION"
      type: MANUAL
    };
    option (wix.http.infer_fieldmask) = {
      from: "settings"
      fieldmask: "field_mask"
    };
  }

  rpc DeleteSettings (DeleteSettingsRequest) returns (DeleteSettingsResponse) {
    option (wix.api.permission) = {
      name: "DEV_CENTER_UPDATE_PERMISSION"
      type: MANUAL
    };
    option (wix.api.required) = "DeleteSettingsRequest.id";
  }

  rpc QuerySettings (QuerySettingsRequest) returns (QuerySettingsResponse) {
    option (google.api.http).post = "/v1/plans/settings/query";
    option (wix.api.permission) = {
      name: "DEVCENTER.PLAN_READ"
      type: MANUAL
    };
  }
}

message CreatePlanRequest {
  // Plan to be created.
  Plan plan = 1;
}

message CreatePlanResponse {
  // The created Plan.
  Plan plan = 1;
}

message GetPlanRequest {
  // ID of the entity to retrieve.
  string id = 1 [(wix.api.format) = GUID];
}

message GetPlanResponse {
  // The requested Plan.
  Plan plan = 1;
}

message UpdatePlanDraftRequest {
  // Plan to be updated, may be partial.
  Plan plan = 1;
  //Set of fields to update, Fields that aren't included in `fieldMask.paths` are ignored.
  google.protobuf.FieldMask field_mask = 2;
}

message UpdatePlanDraftResponse {
  // Updated Plan.
  Plan plan = 1;
}

message QueryPlansRequest {
  // WQL expression.
  wix.devcenter.plans.v1.upstream.wix.query.CursorQuery query = 1;
}

message QueryPlansResponse {
  // List of Plans.
  repeated Plan plans = 1;
  // Paging metadata
  wix.devcenter.plans.v1.upstream.wix.common.CursorPagingMetadata paging_metadata = 2;
}

message PublishPlanRequest {
  // Plan ID.
  string plan_id = 1 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
}

message SetExternalBillingRequest {
  // app id.
  repeated string app_ids = 1 [(wix.api.format) = GUID, (.wix.api.minSize) = 1, (.wix.api.maxSize) = 10];
  bool external_billing = 2;
}

message SetExternalBillingResponse {
  // app id.
  repeated string successful_ids = 1 [(wix.api.format) = GUID, (.wix.api.minSize) = 0, (.wix.api.maxSize) = 1000];
  repeated string failed_ids = 2 [(wix.api.format) = GUID, (.wix.api.minSize) = 0, (.wix.api.maxSize) = 1000];
}

message PublishPlanResponse {
}

message CreateFeatureRequest {
  // Feature to be created.
  Feature feature = 1;
}

message CreateFeatureResponse {
  // Created feature.
  Feature feature = 1;
}

message UpdateFeatureRequest {
  // Feature to be updated.
  Feature feature = 1;
  //Set of fields to update, Fields that aren't included in `fieldMask.paths` are ignored.
  google.protobuf.FieldMask field_mask = 2;
}

message UpdateFeatureResponse {
  // Updated feature.
  Feature feature = 1;
}

message GetFeatureRequest {
  // ID of the entity to retrieve.
  string id = 1 [(wix.api.format) = GUID];
}

message GetFeatureResponse {
  // The requested feature.
  Feature feature = 1;
}

message DeleteFeatureRequest {
  // ID of the entity to delete.
  string id = 1 [(wix.api.format) = GUID];
}

message DeleteFeatureResponse {
}

message QueryFeaturesRequest {
  // WQL expression.
  wix.devcenter.plans.v1.upstream.wix.query.CursorQuery query = 1;
}

message QueryFeaturesResponse {
  // List of features.
  repeated Feature features = 1;
  // Paging metadata
  wix.devcenter.plans.v1.upstream.wix.common.CursorPagingMetadata paging_metadata = 2;
}

message CreatePlanTranslationRequest {
  // Plan to be created.
  PlanTranslation plan_translation = 1;
}

message CreatePlanTranslationResponse {
  // The created Plan.
  PlanTranslation plan_translation = 1;
}

message GetPlanTranslationRequest {
  // ID of the entity to retrieve.
  string id = 1 [(wix.api.format) = GUID];
}

message GetPlanTranslationResponse {
  // The requested Plan.
  PlanTranslation plan_translation = 1;
}

message UpdatePlanTranslationRequest {
  // Plan to be updated, may be partial.
  PlanTranslation plan_translation = 1;
  //Set of fields to update, Fields that aren't included in `fieldMask.paths` are ignored.
  google.protobuf.FieldMask field_mask = 2;
}

message UpdatePlanTranslationResponse {
  // Updated Plan.
  PlanTranslation plan_translation = 1;
}

message DeletePlanTranslationRequest {
  // ID of the entity to delete.
  string id = 1 [(wix.api.format) = GUID];
}

message DeletePlanTranslationResponse {
}

message QueryPlanTranslationsRequest {
  // WQL expression.
  wix.devcenter.plans.v1.upstream.wix.query.CursorQuery query = 1;
}

message QueryPlanTranslationsResponse {
  // List of Plans.
  repeated PlanTranslation plan_translations = 1;
  // Paging metadata
  wix.devcenter.plans.v1.upstream.wix.common.CursorPagingMetadata paging_metadata = 2;
}

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

message CompareResponse {
  // the differences between the DRAFT and the PUBLISHED states
  repeated Difference differences = 1;
}


message CreateSettingsRequest {
  // Plan to be created.
  Settings settings = 1;
}

message CreateSettingsResponse {
  // The created Plan.
  Settings settings = 1;
}

message GetSettingsRequest {
  // ID of the entity to retrieve.
  string id = 1 [(wix.api.format) = GUID];
}

message GetSettingsResponse {
  // The requested Plan.
  Settings settings = 1;
}

message UpdateSettingsRequest {
  // Plan to be updated, may be partial.
  Settings settings = 1;
  //Set of fields to update, Fields that aren't included in `fieldMask.paths` are ignored.
  google.protobuf.FieldMask field_mask = 2;
}

message UpdateSettingsResponse {
  // Updated Plan.
  Settings settings = 1;
}

message DeleteSettingsRequest {
  // ID of the entity to delete.
  string id = 1 [(wix.api.format) = GUID];
}

message DeleteSettingsResponse {
}

message QuerySettingsRequest {
  // WQL expression.
  wix.devcenter.plans.v1.upstream.wix.query.CursorQuery query = 1;
}

message QuerySettingsResponse {
  // List of Plans.
  repeated Settings settings = 1;
  // Paging metadata
  wix.devcenter.plans.v1.upstream.wix.common.CursorPagingMetadata paging_metadata = 2;
}
