syntax = "proto3";

package wix.payment.api.pay.v2.upstream.wix.common;

option java_multiple_files = true;
option java_package = "com.wix.payment.api.pay.v2.upstream.wix.common";

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

// A common address format to use if you plan to store addresses in your service
// todo: remove unused fields from decomposition and remove validations
// Physical address
message Address {
  option (.wix.api.decomposite_of) = "wix.common.Address";
  option (.wix.api.decomposition_minimum_fields) = {
    field: "country"
    field: "subdivision"
    field: "city"
    field: "postal_code"
    field: "street_address"
    field: "formatted_address"
  };
  option (.wix.api.decomposition_minimum_fields) = {
    field: "country"
    field: "subdivision"
    field: "city"
    field: "postal_code"
    field: "address_line"
    field: "address_line_2"
    field: "formatted_address"
  };
  // address country
  google.protobuf.StringValue country = 1 [(.wix.api.format) = COUNTRY]; // Country code.
  // address subdivision (state, region etc)
  google.protobuf.StringValue subdivision = 2 [(.wix.api.maxLength) = 100]; // Subdivision. Usually a state, region, prefecture, or province code, according to [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2).
  // address city
  google.protobuf.StringValue city = 3 [(.wix.api.pii) = true, (.wix.api.maxLength) = 100]; // City name.
  // address postal code
  google.protobuf.StringValue postal_code = 4 [(.wix.api.pii) = true, (.wix.api.minLength) = 1, (.wix.api.maxLength) = 10]; // Zip/postal code.
  oneof street {
    // Street name and number.
    StreetAddress street_address = 5;
    // Street in one line format
    google.protobuf.StringValue address_line = 6 [(.wix.api.pii) = true, (.wix.api.minLength) = 1, (.wix.api.maxLength) = 1000]; // Main address line, usually street and number as free text.
  }
  // address line 2
  google.protobuf.StringValue address_line_2 = 7 [(.wix.api.pii) = true, (.wix.api.minLength) = 1, (.wix.api.maxLength) = 1000]; // Free text providing more detailed address info. Usually contains Apt, Suite, and Floor.
  // full address in one line format
  google.protobuf.StringValue formatted_address = 8 [(.wix.api.pii) = true, (.wix.api.maxLength) = 1000, (.wix.api.field_exposure) = PRIVATE]; // A string containing the full address of this location.
  // hint for address
  google.protobuf.StringValue hint = 9 [(.wix.api.pii) = true, (.wix.api.maxLength) = 1000, (.wix.api.field_exposure) = PRIVATE]; // Free text to help find the address.
  // address geo code
  AddressLocation geocode = 10 [(.wix.api.field_exposure) = PRIVATE]; // Coordinates of the physical address.
  // full name of the country
  google.protobuf.StringValue country_fullname = 11 [(.wix.api.pii) = false, (.wix.api.maxLength) = 100, (.wix.api.field_exposure) = PRIVATE]; // Country full name.
  // full name of the subdivision
  google.protobuf.StringValue subdivision_fullname = 13 [(.wix.api.pii) = false, (.wix.api.maxLength) = 100, (.wix.api.field_exposure) = PRIVATE]; // Subdivision full name.
  // list of subdivision information
  repeated Subdivision subdivisions = 12 [(.wix.api.field_exposure) = PRIVATE, (.wix.api.maxSize) = 6]; // Multi-level subdivisions from top to bottom.
}

message Subdivision {
  option (.wix.api.decomposite_of) = "wix.common.Subdivision";
  enum SubdivisionType {
    UNKNOWN_SUBDIVISION_TYPE = 0;
    ADMINISTRATIVE_AREA_LEVEL_1 = 1; // State
    ADMINISTRATIVE_AREA_LEVEL_2 = 2; // County
    ADMINISTRATIVE_AREA_LEVEL_3 = 3; // City/town
    ADMINISTRATIVE_AREA_LEVEL_4 = 4; // Neighborhood/quarter
    ADMINISTRATIVE_AREA_LEVEL_5 = 5; // Street/block
    COUNTRY = 6; // ADMINISTRATIVE_AREA_LEVEL_0. Indicates the national political entity, and is typically the highest order type returned by the Geocoder.
  }
  option (.wix.api.decomposition_minimum_fields) = {
    field: "code"
  };
  // Short subdivision code.
  string code = 1 [(.wix.api.maxLength) = 100];
  // Subdivision full name.
  string name = 2 [(.wix.api.maxLength) = 100];
  // Subdivision level
  SubdivisionType type = 3 [(.wix.api.field_exposure) = PRIVATE];
  // Free text description of subdivision type.
  google.protobuf.StringValue type_info = 4 [(.wix.api.field_exposure) = PRIVATE, (.wix.api.maxLength) = 1000];
}

message StreetAddress {
  option (.wix.api.decomposite_of) = "wix.common.StreetAddress";
  option (.wix.api.decomposition_minimum_fields) = {
    field: "number"
    field: "name"
  };
  // Street number.
  string number = 1 [(.wix.api.pii) = true, (.wix.api.maxLength) = 100];
  // Street name.
  string name = 2 [(.wix.api.pii) = true, (.wix.api.maxLength) = 100];
  // Apartment number.
  string apt = 3 [(.wix.api.pii) = true, (.wix.api.maxLength) = 100, (.wix.api.field_exposure) = PRIVATE];
  // Optional address line 1
  google.protobuf.StringValue formatted_address_line = 4 [(.wix.api.pii) = true, (.wix.api.maxLength) = 100, (.wix.api.field_exposure) = PRIVATE];
}

//Contact details for the address
message AddressContactDetails {
  option (.wix.api.decomposite_of) = "wix.common.AddressContactDetails";
  option (.wix.api.decomposition_minimum_fields) = {
    field: "full_name"
  };
  // Contact's full name.
  google.protobuf.StringValue full_name = 1 [(.wix.api.pii) = true, (.wix.api.maxLength) = 100];
  // Contact's phone number.
  google.protobuf.StringValue phone = 2 [(.wix.api.pii) = true, (.wix.api.format) = PHONE];
  // Contact's company name.
  google.protobuf.StringValue company = 3 [(.wix.api.maxLength) = 100];
  // Email associated with the address.
  google.protobuf.StringValue email = 4 [(.wix.api.pii) = true, (.wix.api.format) = EMAIL];
}

//Full contact details for an address
message FullAddressContactDetails {
  option (.wix.api.decomposite_of) = "wix.common.FullAddressContactDetails";
  option (.wix.api.decomposition_minimum_fields) = {
    field: "first_name"
    field: "last_name"
  };
  option (.wix.api.decomposition_minimum_fields) = {
    field: "full_name"
  };
  // Contact's first name.
  google.protobuf.StringValue first_name = 1 [(.wix.api.pii) = true, (.wix.api.maxLength) = 100];
  // Contact's last name.
  google.protobuf.StringValue last_name = 2 [(.wix.api.pii) = true, (.wix.api.maxLength) = 80];
  // Contact's full name.
  google.protobuf.StringValue full_name = 8 [(.wix.api.pii) = true, (.wix.api.maxLength) = 100, (.wix.api.field_exposure) = PRIVATE];
  // Contact's phone number.
  google.protobuf.StringValue phone = 3 [(.wix.api.pii) = true, (.wix.api.format) = PHONE];
  // Contact's company name.
  google.protobuf.StringValue company = 4 [(.wix.api.maxLength) = 100];
  // Email associated with the address.
  google.protobuf.StringValue email = 5 [(.wix.api.pii) = true, (.wix.api.format) = EMAIL];
  // Tax info. Currently usable only in Brazil.
  VatId vat_id = 7;
}

message VatId {
  option (.wix.api.decomposite_of) = "wix.common.VatId";
  option (.wix.api.decomposition_minimum_fields) = {
    field: "id"
    field: "type"
  };
  string id = 1 [(.wix.api.pii) = true, (.wix.api.maxLength) = 50]; // Customer's tax ID.
  /*
  Tax type.

  Supported values:
  + `CPF`: for individual tax payers
  + `CNPJ`: for corporations
  */
  VatType type = 2;
}

// tax info types
enum VatType {
  UNSPECIFIED = 0;
  CPF = 1; // CPF - for individual tax payers.
  CNPJ = 2; // CNPJ - for corporations
}

message AddressLocation {
  option (.wix.api.decomposite_of) = "wix.common.AddressLocation";
  option (.wix.api.decomposition_minimum_fields) = {
    field: "latitude"
    field: "longitude"
  };
  // Address latitude.
  google.protobuf.DoubleValue latitude = 1 [(.wix.api.pii) = true];
  // Address longitude.
  google.protobuf.DoubleValue longitude = 2 [(.wix.api.pii) = true];
}
