syntax = "proto3";

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

import "wix/api/validations.proto";
import "wix/api/entity.proto";
import "wix/api/annotations.proto";
import "google/protobuf/wrappers.proto";
import "google/protobuf/timestamp.proto";

/**
  A Plan is an entity that embodies the pricing structures available for apps featured in the devcenter.
  It serves as a comprehensive representation of the diverse pricing plans that users can select from
  to access varying levels of features and services within the application ecosystem
 */
message Plan {

  option (wix.api.entity) = {
    fqdn: "wix.devcenter.plans.v1.plan"
    segment: USERS,
    domain_events: {
      deleted_include_entity: true,
      updated_include_modified_fields: true

    }
    domain_events_read_permission: "APP_MARKET.PLANS_DOMAIN_EVENTS_READ"
  };

  // entity ID for SDL purposes only.
  string id = 1 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
  // Plan ID.
  string plan_id = 2 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
  // The app id of the plan
  string app_id = 3 [(.wix.api.format) = GUID, (wix.api.readOnly) = true];
  // Plan name
  google.protobuf.StringValue name = 4 [(wix.api.maxLength) = 50];
  // The plan's slug, unique per app, identifies the plan in premium services
  google.protobuf.StringValue vendor_id = 5 [(wix.api.readOnly) = true];
  // Mark this plan as most popular for UI purposes
  bool most_popular = 6;
  // Can be shown as bullets / text (list of size 1)
  repeated string description = 7 [(wix.api.maxSize) = 4];
  // Indicates in which places the plan is visible to the user
  repeated Visibility visible_in_pages = 8 [(wix.api.maxSize) = 3];
  // List of plan's payment details, all possible payment options
  repeated Payment payment = 9 [(wix.api.maxSize) = 10];
  // Plan's supported features, which are the features that are available for the plan and presented in the package picker
  repeated SupportedFeature supported_features = 10 [(wix.api.maxSize) = 50];
  // Plan's status - Draft or Published.
  Status status = 11;
  // Plan's free trial days. managed by the developer
  google.protobuf.Int32Value free_trial_days = 12;
  // Revision number, which increments by 1 each time the Plan is updated.
  google.protobuf.Int64Value revision = 13 [(wix.api.readOnly) = true];
  // Date and time the Plan was created.
  google.protobuf.Timestamp created_date = 14 [(wix.api.readOnly) = true];
  // Date and time the Plan was last updated.
  google.protobuf.Timestamp updated_date = 15 [(wix.api.readOnly) = true];


  option (.wix.api.domain_event) = {
    event_type: CREATED
  };
  option (.wix.api.domain_event) = {
    event_type: UPDATED
  };
  option (.wix.api.domain_event) = {
    event_type: DELETED
  };
}

enum Visibility {
  UNKNOWN_VISIBILITY = 0;
  VISIBLE_IN_APP_PAGE = 1;
  VISIBLE_IN_PACKAGE_PICKER = 2;
}

enum Status {
  UNKNOWN_STATUS = 0;
  DRAFT = 1;
  PUBLISHED = 2;
  ARCHIVED = 3;
}

enum PaymentExtensions {
  UNKNOWN_EXTENTIONS = 0;
  METERED_BILLING = 1;
}

message Payment {
  // Select recurring with all the details / one time payment
  PaymentType payment_type = 1;
  oneof payment_type_options {
    option (.wix.api.aligned_with_enum).field = "payment_type";
    RecurringOptions recurring_options = 2;
  }
  // Amount to charge on every cycle
  google.protobuf.StringValue amount = 3 [(.wix.api.decimalValue) = {gte: "0.00"}];
  // Additional plan data
  PaymentExtensions payment_extensions = 4;
  oneof payment_extensions_options {
    option (.wix.api.aligned_with_enum).field = "payment_extensions";
    // Additional options for plans that have metered billing payment
    MeteredBillingOptions metered_billing_options = 5;
  }
  // Can be shown instead of plan price - used for dynamic plans
  google.protobuf.StringValue custom_payment_title = 6;
  bool external_billing_payment = 7; //classification for payment type external/wix payment systems
}

message MeteredBillingOptions {
  // Additional info about the plan
  google.protobuf.StringValue additional_info = 1;
  // Additional charges price, developer can set the price for each additional charge
  //  google.protobuf.DoubleValue additional_charges_price = 2;  //Todo waiting for liza's response
  // Index to declare where the price that the developer set will be shown. index of additional_info string
  //  google.protobuf.Int32Value additional_charge_price_index = 3; //Todo waiting for liza's response
  //Todo check if currency is needed
}


message RecurringOptions {
  // Monthly, yearly etc
  CycleUnit cycle_unit = 1;
  // Count of cycles - 3 months, 2 years etc
  int32 count = 2;
}

enum CycleUnit {
  UNKNOWN_CYCLE_UNIT = 0;
  MONTHLY = 1;
  YEARLY = 2;
}

enum PaymentType {
  UNKNOWN_PAYMENT_TYPE = 0;
  RECURRING = 1;
  ONE_TIME = 2;
}

message SupportedFeature {
  // Id of feature stored in features secondary service
  string feature_id = 1 [(.wix.api.format) = GUID];
  // Custom text to present instead of marking that the plan is supported (instead of "V")
  google.protobuf.StringValue custom_text = 3;
}

message Difference {
  // the code that indicates what changed in the pricing level
  DifferenceCode difference_code = 1;

  // the level of the change
  DifferenceLevel level = 2;
}

enum DifferenceCode {
  UNKNOWN = 0;
  PAID_TO_FREE = 1;
  OTHER = 2;
}

enum DifferenceLevel {
  INFO = 0;
  WARNING = 1;
}


