syntax = "proto3";

package com.wixpress.appservice.api.upstream.wix.forms.v4;
option java_package = "com.wixpress.appservice.api.upstream.wix.forms.v4";

import "wix/api/validations.proto";
import "wix/api/annotations.proto";

message PostSubmissionTriggers {
    option (.wix.api.decomposite_of) = "wix.forms.v4.PostSubmissionTriggers";
  // Upserts a contact from the submission data.
  UpsertContact upsert_contact = 1;
  reserved 2;
}

message UpsertContact {
    option (.wix.api.decomposite_of) = "wix.forms.v4.UpsertContact";
  // Fields mapping (target field mapped to corresponding contact field).
  map <string, FormFieldContactInfo> fields_mapping = 1 [(.wix.api.maxSize) = 250];
  /*
  List of contact label keys.
  [Contact labels](https://support.wix.com/en/article/adding-labels-to-contacts-in-your-contact-list)
  help categorize contacts.
  */
  repeated string labels = 2 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 100, (.wix.api.maxSize) = 20];
}

message FormFieldContactInfo {
    option (.wix.api.decomposite_of) = "wix.forms.v4.FormFieldContactInfo";
  // Field mapped to contacts.
  ContactField contact_field = 1;
  // Additional info for the given field in contacts.
  oneof additional_info {
    // Email info.
    EmailInfo email_info = 2;
    // Phone info.
    PhoneInfo phone_info = 3;
    // Address info.
    AddressInfo address_info = 4;
    // Custom field info.
    CustomFieldInfo custom_field_info = 5;
    // Subscription info
    SubscriptionInfo subscription_info = 6;
  }

  enum ContactField {
    UNDEFINED = 0 [(.wix.api.enum_maturity) = NOT_IMPLEMENTED];
    FIRST_NAME = 1;
    LAST_NAME = 2;
    COMPANY = 3;
    POSITION = 4;
    EMAIL = 5;
    PHONE = 6;
    ADDRESS = 7;
    BIRTHDATE = 8;
    CUSTOM_FIELD = 9;
    SUBSCRIPTION = 10;
    VAT_ID = 11;
  }

  message EmailInfo {
    option (.wix.api.decomposite_of) = "wix.forms.v4.EmailInfo";
    // Email tag.
    Tag tag = 1;

    enum Tag {
      UNTAGGED = 0;
      MAIN = 1;
    }
  }

  message PhoneInfo {
    option (.wix.api.decomposite_of) = "wix.forms.v4.PhoneInfo";
    // Phone tag.
    Tag tag = 1;

    enum Tag {
      UNTAGGED = 0;
      MAIN = 1;
    }
  }

  message AddressInfo {
    option (.wix.api.decomposite_of) = "wix.forms.v4.AddressInfo";
    // Address tag.
    Tag tag = 1;

    enum Tag {
      UNTAGGED = 0;
      HOME = 1;
    }
  }

  message CustomFieldInfo {
    option (.wix.api.decomposite_of) = "wix.forms.v4.CustomFieldInfo";
    // Custom field key.
    string key = 1 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 500];
  }

  message SubscriptionInfo {
    option (.wix.api.decomposite_of) = "wix.forms.v4.SubscriptionInfo";
    // Subscription consent opt in level, either single or double confirmation.
    // Default: SINGLE_CONFIRMATION
    OptInLevel opt_in_level = 1;

    enum OptInLevel {
      UNKNOWN = 0;
      SINGLE_CONFIRMATION = 1;
      DOUBLE_CONFIRMATION = 2;
    }
  }
}
