syntax = "proto3";

package wix.infra.dataextensions.v1;
option java_package = "com.wixpress.infra.dataextensions.v1";

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

/**
 A Data Extension Schema is the [JSON schema](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/schema-plugins/the-json-schema) within a [schema plugin extension](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/schema-plugins/about-schema-plugin-extensions) defining `extendedFields` that are added to a Wix API's service object.
 */
message DataExtensionSchema {
  //flynt-disable missing-extensible
  option (wix.api.entity) = {
    fqdn: "wix.data_extensions.v1.data_extension_schema"
    segment: PUBLIC
    appendix_files: {
      type: AUTO_VELO
      path: "appendices/velo"
    };
    appendix_files: {
      type: DOCS_CONF
      path: "appendices/docs"
    }
    domain_events: {
      updated_include_modified_fields: true
    }
    app_def_id: "553ddc93-3b34-450a-ad71-128be92586ec",
    domain_events_read_permission: "DATA_EXTENSION_SCHEMA.READ",
  };

  // Triggered when a data extension schema is created.
  option (wix.api.domain_event) = {
    event_type: CREATED
    maturity: GA
    exposure: PUBLIC
  };
  // Triggered when a data extension schema is updated.
  option (wix.api.domain_event) = {
    event_type: UPDATED
    maturity: GA
    exposure: PUBLIC
  };
  // Triggered when a data extension schema is deleted.
  option (wix.api.domain_event) = {
    event_type: DELETED
    maturity: GA
    exposure: PUBLIC
  };

  google.protobuf.StringValue id = 1 [(wix.api.format) = GUID, (wix.api.readOnly) = true, (wix.api.immutable) = true]; // Schema ID.
  google.protobuf.StringValue fqdn = 2 [(wix.api.immutable) = true, (wix.api.maxLength) = 255]; // FQDN of the entity this schema extends.
  /*
  Namespace for this schema. For example, an app creating schemas might use their app name as a namespace.  
  When a site owner creates a user-defined schema, the namespace is: `_user_fields`.
  */
  google.protobuf.StringValue namespace = 3 [(wix.api.immutable) = true, (wix.api.maxLength) = 164];
  /*
  // Schema definition in [JSON schema format](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/schema-plugins/the-json-schema) with the following [vocab](https://docs.json-everything.net/schema/vocabs/) extension:
  ```
{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://wixapis.com/v1/json-schema/extensions",
    "$vocabulary": {
        "https://wixapis.com/v1/json-schema/extensions/vocab/data-extensions": true
    },
    "$dynamicAnchor": "meta",
    "title": "Wix' data-extensions vocabulary meta schema",
    "type": [
        "object",
        "boolean"
    ],
    "properties": {
        "x-wix-permissions": {
            "type": "object",
            "description": "list of identity types that are allowed reading schema properties",
            "properties": {
                "read": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "enum": [
                            "apps",
                            "owning-app",
                            "users",
                            "users-of-users"
                        ]
                    }
                },
                "write": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "enum": [
                            "apps",
                            "owning-app",
                            "users",
                            "users-of-users"
                        ]
                    }
                }
            }
        },
        "x-wix-display": {
            "type": "object",
            "description": "field display properties",
            "schema": {
                "properties": {
                    "placeholder": {
                        "type": "string",
                        "maxLength": 255,
                        "description": "placeholder text for input fields"
                    },
                    "label": {
                        "type": "string",
                        "maxLength": 255,
                        "description": "label of the input fields"
                    },
                    "hint": {
                        "type": "string",
                        "maxLength": 255,
                        "description": "a short explanation that appears next to the input field"
                    }
                }
            }
        }
    }
}
  ```
  */
  google.protobuf.Struct json_schema = 5;
  google.protobuf.Timestamp updated_date = 6 [(wix.api.readOnly) = true]; // Date and time the schema was last updated.
  google.protobuf.Timestamp created_date = 7 [(wix.api.readOnly) = true]; // Date and time the schema was created.
  google.protobuf.Int64Value revision = 8 [(wix.api.readOnly) = true]; // Revision number, which increments by 1 each time the schema is updated. To prevent conflicting changes, the existing revision must be used when updating a schema.

  google.protobuf.StringValue app_def_id = 101 [(wix.api.format) = GUID, (wix.api.readOnly) = true, (wix.api.field_exposure) = PRIVATE]; // app def id of the app in the given namespace

  google.protobuf.Int32Value max_limit_bytes = 9 [(wix.api.readOnly) = true]; // Maximum allowed schema size in bytes.
  google.protobuf.Int32Value current_size_bytes = 10 [(wix.api.readOnly) = true]; // Current schema size in bytes.
  string extension_point = 11 [(wix.api.immutable) = true, (wix.api.maxLength) = 20, (wix.api.field_maturity) = ALPHA]; // Name of the specific entity field this schema is extending, or `"ROOT"` for extensions for the entire entity. Default: `"ROOT"`.
  State state = 12 [(wix.api.readOnly) = true, (wix.api.field_exposure) = PRIVATE]; // Indicates whether the schema is in production or draft state.

  enum State {
    UNKNOWN_STATUS = 0 [(.wix.api.enum_exposure) = PRIVATE, (.wix.api.enum_maturity) = NOT_IMPLEMENTED];
    PRODUCTION = 1 [(.wix.api.enum_exposure) = PRIVATE]; // Production schema, this is normal state for both user-defined and app-defined schemas.
    DRAFT = 2 [(.wix.api.enum_exposure) = PRIVATE]; // Draft schema, this is meant for app-defined schemas during app development.
  }
}
