syntax = "proto3";

package com.wixpress.appservice.api;

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

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

// An extension for adding data collections to a site when the app is installed.
message DataComponent {
  // Token used by Wix to add collections to a site during app installation. For internal use only.
  google.protobuf.StringValue collections_token = 10 [(wix.api.format) = GUID, (wix.api.field_exposure) = PRIVATE];

  // Data collections automatically added to a site when the app is installed.
  repeated Collection collections = 11 [(wix.api.maxSize) = 100];


  message Collection {
    // Full collection ID with namespace. Deprecated, use id_suffix instead.
    string id = 1 [(wix.api.maxLength) = 256, (wix.api.field_exposure) = PRIVATE, deprecated = true, (.wix.api.field_deprecated) = {
      replaced_by: "id_suffix",
      target_removal_date: "2025-11-30"
    }];

    // Collection ID suffix. The app namespace is automatically prepended in the CMS.
    // For example, the full ID for `my-products-1` becomes `@company/app-name/my-products-1`.
    string id_suffix = 4 [(wix.api.maxLength) = 256];

    // Full URL for the JSON schema defining the collection structure.
    // Must be in JSON format.
    string schema_url = 2 [(wix.api.format) = WEB_URL, (wix.api.field_exposure) = PRIVATE, deprecated = true, (.wix.api.field_deprecated) = {
      target_removal_date: "2025-11-30"
    }];

    // Optional URL for a JSON file containing initial data to populate the collection with.
    // Must be in JSON Lines format.
    google.protobuf.StringValue initial_data_url = 3 [(wix.api.format) = WEB_URL, (wix.api.field_exposure) = PRIVATE, deprecated = true, (.wix.api.field_deprecated) = {
      target_removal_date: "2025-11-30"
    }];

    // Collection's display name as shown in the CMS. For example, `My First Collection`.
    google.protobuf.StringValue display_name = 5 [(wix.api.minLength) = 1, (wix.api.maxLength) = 1000];

    // Field whose value the CMS displays to represent the collection item when referenced in a different collection.
    google.protobuf.StringValue display_field = 17 [(wix.api.minLength) = 1, (wix.api.maxLength) = 1000];

    // Collection's field structure.
    repeated Field fields = 10 [(wix.api.minSize) = 1, (wix.api.maxSize) = 1000];

    // Levels of permission for accessing and modifying data, defined by the lowest role needed to perform each action.
    DataPermissions data_permissions = 18;

    // Indexes defined for the collection. An index is a map of a collection's data, organized according to specific fields to increase query speed.
    repeated Index indexes = 20 [(wix.api.maxSize) = 3];

    // Optional initial data to populate the collection with.
    repeated google.protobuf.Struct initial_data = 30 [(wix.api.maxSize) = 1000];
  }

  message Field {
    // Unique identifier for the field. For example, `firstName`.
    string key = 1 [(wix.api.minLength) = 1, (wix.api.maxLength) = 1000];

    // Field's display name when displayed in the CMS. For example, `First Name`.
    google.protobuf.StringValue display_name = 18 [(wix.api.minLength) = 1, (wix.api.maxLength) = 1000];

    // Field's data type.
    //
    // Learn more about [data types in Wix Data](https://dev.wix.com/docs/rest/business-solutions/cms/data-types-in-wix-data).
    Type type = 3;

    // Metadata for complex data types. This property only exists for references, multi-references, objects, and arrays.
    oneof type_options {
      option (.wix.api.aligned_with_enum).field = "type";

      // Metadata for a reference field.
      ReferenceOptions reference_options = 1001;
      // Metadata for a multi-reference field.
      MultiReferenceOptions multi_reference_options = 1002;
      // Metadata for an object field.
      ObjectOptions object_options = 1003;
      // Metadata for an array field.
      ArrayOptions array_options = 1004;
    }

    // Whether the field is encrypted.
    bool encrypted = 8;

    // Field description.
    google.protobuf.StringValue description = 10 [(wix.api.maxLength) = 16000];

    message ReferenceOptions {
      // Referenced collection ID.
      string referenced_collection_id = 1 [(wix.api.minLength) = 1, (wix.api.maxLength) = 256];
    }

    message MultiReferenceOptions {
      // Referenced collection ID.
      string referenced_collection_id = 1 [(wix.api.minLength) = 1, (wix.api.maxLength) = 256];
    }

    message ObjectOptions {
      message ObjectField {
        // Field ID.
        string key = 1 [(wix.api.minLength) = 1, (wix.api.maxLength) = 1000];
        // Display name for the field.
        google.protobuf.StringValue display_name = 7 [(wix.api.minLength) = 1, (wix.api.maxLength) = 1000];
        // Field type.
        //
        // Learn more about [data types in Wix Data](https://dev.wix.com/docs/rest/business-solutions/cms/data-types-in-wix-data).
        Type type = 3;
        // Metadata for complex data types. This property only exists for references, multi-references, objects, and arrays.
        oneof type_options {
          option (.wix.api.aligned_with_enum).field = "type";

          // Metadata for an object field.
          ObjectOptions object_options = 1003;
          // Metadata for an array field.
          ArrayOptions array_options = 1004;
        }
      }

      // Fields within the object.
      repeated ObjectField fields = 1 [(wix.api.maxSize) = 1000];
    }

    message ArrayOptions {
      // Element's data type.
      Type element_type = 1;
      // Metadata for complex data types. This property only exists for references, multi-references, objects, and arrays.
      oneof element_type_options {
        option (.wix.api.aligned_with_enum).field = "element_type";

        // Metadata for an object field.
        ObjectOptions object_options = 1003;
        // Metadata for an array field.
        ArrayOptions array_options = 1004;
      }
    }

    enum Type {
      UNKNOWN_FIELD_TYPE = 0 [(.wix.api.enum_maturity) = NOT_IMPLEMENTED];
      // Plain-text string.
      TEXT = 1;
      // Number.
      NUMBER = 2;
      // Date string in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format: `YYYY-MM-DD`.
      DATE = 3;
      // [JavaScript Date object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) (SDK) or an object in the following format: `"someFieldKey": { "$date": "YYYY-MM-DDTHH:mm:ss.sssZ"}`.
      DATETIME = 4;
      // Web URL or a [Media Manager](https://dev.wix.com/docs/rest/assets/media/media-manager/introduction) URL.
      IMAGE = 5;
      // Boolean `true` or `false` value.
      BOOLEAN = 6;
      // Web URL or a [Media Manager](https://dev.wix.com/docs/rest/assets/media/media-manager/introduction) URL.
      DOCUMENT = 7;
      // URL in one of the following formats: `http://`, `https://`, `ftp://`, `mailto:`, `sms:`, `tel:`.
      URL = 8;
      // [Rich-text](https://dev.wix.com/docs/rest/articles/getting-started/rich-text) string that may contain a subset of HTML tags.
      RICH_TEXT = 9;
      // Web URL or a [Media Manager](https://dev.wix.com/docs/rest/assets/media/media-manager/introduction) URL.
      VIDEO = 10;
      // Any field type.
      ANY = 11;
      // Array of strings.
      ARRAY_STRING = 12;
      // Array of documents: web or [Media Manager](https://dev.wix.com/docs/rest/assets/media/media-manager/introduction) URLs.
      ARRAY_DOCUMENT = 13;
      // Web URL or a [Media Manager](https://dev.wix.com/docs/rest/assets/media/media-manager/introduction) URL.
      AUDIO = 14;
      // Time string in `hh:mm:ss.SSS` format.
      TIME = 15;
      // Language codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes) format. These may include country codes in [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#officially_assigned_code_elements) format.
      LANGUAGE = 16;
      // [Rich content](https://dev.wix.com/docs/ricos/getting-started/introduction).
      RICH_CONTENT = 17;
      // Array of web or [Media Manager](https://dev.wix.com/docs/rest/assets/media/media-manager/introduction) URLs.
      MEDIA_GALLERY = 18;
      // Physical [address object](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-types-in-wix-data#address-object).
      ADDRESS = 19;

      // Reference to another item in another collection. See [Query Referenced Data Items](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/query-referenced-data-items) to learn about item references.
      //
      // If you select this type, then you must pass the `referencedCollectionId` field as well.
      REFERENCE = 21;
      // References to multiple items in another collection. See [Query Referenced Data Items](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/query-referenced-data-items) to learn about item references.
      MULTI_REFERENCE = 22;
      // JSON object.
      OBJECT = 23;
      // Array.
      ARRAY = 24;

    }

  }

  // Data permissions defined by access level for each action.
  message DataPermissions {

    // Access level required to read data items.
    AccessLevel item_read = 2;

    // Access level required to insert data items.
    AccessLevel item_insert = 3;

    // Access level required to update data items.
    AccessLevel item_update = 4;

    // Access level required to remove data items.
    AccessLevel item_remove = 5;

    // Describes who can perform certain action.
    // Each level includes all levels below it (except UNDEFINED).
    enum AccessLevel {
      // Not set.
      UNDEFINED = 0 [(wix.api.enum_maturity) = NOT_IMPLEMENTED];
      // Anyone, including site visitors.
      ANYONE = 1;
      // Any signed-in user, including site members and collaborators.
      SITE_MEMBER = 2;
      // Any signed-in user, but site members only have access to their own items.
      SITE_MEMBER_AUTHOR = 3;
      // Site collaborator that has a role with CMS access permission.
      CMS_EDITOR = 4;
      // CMS administrators and users or roles granted special access.
      PRIVILEGED = 5;
    }
  }

  message Index {
    // Fields for which the index is defined.
    //
    // Max: 3 fields (for a unique index: 1 field)
    repeated Field fields = 2 [(wix.api.minSize) = 1, (wix.api.maxSize) = 3];

    // Whether the index enforces uniqueness of values in the field for which it is defined.
    // If `true`, the index can have only one field.
    //
    // Default: `false`
    bool unique = 7;

    message Field {

      // Path of the field to index. For example: `title` or `options.price`.
      string path = 1 [(wix.api.minLength) = 1, (wix.api.maxLength) = 128];

      // Sort order for the index. Base on how the data is regularly queried.
      //
      // Default: `ASC`
      Order order = 3;

      // Order determines how values are ordered in the index. This is important when
      // ordering and/or range querying by indexed fields.
      enum Order {
        ASC = 0;
        DESC = 1;
      }
    }
  }

}
