syntax = "proto3";

package com.wixpress.appservice.api;

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

message AutomationTrigger {
    // The name that will be passed with trigger report event to activate an Automation.
    string name = 1 [(wix.api.maxLength) = 80];
    // The name displayed to the user.
    string display_name = 2 [(wix.api.maxLength) = 80];
    // The schema of the payload that will be passed with trigger when activating an Automation.
    SchemaConfig schema_config = 3;
    // flynt-disable unannotated-pii-fields
    // Email template to be shown when user choose this trigger and email action.
    google.protobuf.StringValue email_template_name = 4 [(wix.api.field_exposure) = INTERNAL];

    string deployment_uri = 5 [(.wix.spi.base_uri) = true];
    int32 revision = 6;
}

message SchemaConfig {
    // The fields of the payload as sent in the report event
    repeated SchemaField fields = 1;
    // Dynamic schema service URL.
    // Dynamic schema is used when user needs to choose specific entities from site to activate the Automation.
    // For example form name, purchased product, etc.
    google.protobuf.StringValue dynamic_schema_url = 2 [(wix.api.format) = WEB_URL];
}

message SchemaField {
    // The key as it appears on the report event payload.
    string key = 1;
    // The name displayed to the user.
    string display_name = 2;
    // The field type
    SchemaFieldType field_type = 3;
    // Sample values, values that could show up in the payload of a trigger.
    repeated string sample_values = 4;
    // The field exposure
    Exposure exposure = 5;


    enum Exposure {
        UNKNOWN_EXPOSURE = 0;
        // Not sent to the action provider
        SETUP = 1;
        // Sent to the action provider and usually hidden from user
        HIDDEN = 2;
        // Sent to the action provider and usually shown to user
        EXPOSED = 3;
    }

    message SchemaFieldType {
        oneof fieldType {
            Primitive primitive = 1;
            Simple simple = 2;
            // The field value must conform to the following JSON structure { "timestamp": string, "timeZone": string }, where the timestamp is ISO format UTC, and the time zone is the full name
            // Example: { "timestamp": "2021-03-22T11:41:47.992Z", timeZone: "Asia/Jerusalem" }
            Date date = 3;
        }

        message Primitive {
            PrimitiveType primitive_type = 1;

            enum PrimitiveType {
                UNKNOWN_PRIMITIVE_TYPE = 0;
                TEXT = 1;
                BOOLEAN = 2;
                NUMBER = 3;
            }
        }

        message Simple {
            SimpleType simple_type = 1;

            enum SimpleType {
                UNKNOWN_SIMPLE_TYPE = 0;
                MONEY = 1;
                LINK = 2;
                BACKOFFICE_LINK = 3;
                LIVESITE_LINK = 4;
                MULTILINGUAL = 5;
                IMAGE_LINK = 6;
                GUID = 7;
                EMAIL = 8;
                PHONE = 9;
                CONTACT_ID = 10;
            }
        }

        message Date {
            // Default: false, set this to true if the date is normally a future date, like: Invoice expiration date, Membership renewal date
            google.protobuf.BoolValue allow_negative_offset = 1;
        }
    }
}
