syntax = "proto3";

package wix.common;

option java_multiple_files = true;
option java_package = "com.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

// Physical address
message 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"
    };
    google.protobuf.StringValue country = 1 [(.wix.api.format) = COUNTRY]; // Country code.
    google.protobuf.StringValue subdivision = 2; // Subdivision shorthand. Usually, a short code (2 or 3 letters) that represents a state, region, prefecture, or province. e.g. NY
    google.protobuf.StringValue subdivision_iso_3166_2 = 14 [(.wix.api.maxLength) = 20, (.wix.api.field_exposure) = PRIVATE]; // Subdivision. Usually a state, region, prefecture, or province code, according to [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2), e.g. US-NY
    google.protobuf.StringValue city = 3 [(.wix.api.pii) = true]; // City name.
    google.protobuf.StringValue postal_code = 4 [(.wix.api.pii) = true]; // Zip/postal code.
    oneof street {
        StreetAddress street_address = 5; // Street name and number.
        google.protobuf.StringValue address_line = 6 [(.wix.api.pii) = true]; // Main address line, usually street and number as free text.
    }
    google.protobuf.StringValue address_line_2 = 7 [(.wix.api.pii) = true]; // Free text providing more detailed address info. Usually contains Apt, Suite, and Floor.

    google.protobuf.StringValue formatted_address = 8 [(.wix.api.pii) = true, (.wix.api.field_exposure) = PRIVATE]; // A string containing the full address of this location.
    google.protobuf.StringValue hint = 9 [(.wix.api.pii) = true, (.wix.api.field_exposure) = PRIVATE]; // Free text to help find the address.
    AddressLocation geocode = 10 [(.wix.api.field_exposure) = PRIVATE]; // Coordinates of the physical address.
    google.protobuf.StringValue country_fullname = 11 [(.wix.api.pii) = false, (.wix.api.field_exposure) = PRIVATE]; // Country full name.
    google.protobuf.StringValue subdivision_fullname = 13 [(.wix.api.pii) = false, (.wix.api.field_exposure) = PRIVATE]; // Subdivision full name.
    repeated Subdivision subdivisions = 12 [(.wix.api.field_exposure) = PRIVATE, (.wix.api.maxSize) = 6]; // Multi-level subdivisions from top to bottom.
}

message 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.
    }

    // Subdivision Concordance values
    message StandardDetails {
        google.protobuf.StringValue iso_3166_2 = 1 [(.wix.api.maxLength) = 20]; // subdivision iso-3166-2 code according to [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2). e.g. US-NY, GB-SCT, NO-30
    }

    option (.wix.api.decomposition_minimum_fields) = {
        field: "code"
    };
    string code = 1; // Short subdivision code.
    string name = 2; // Subdivision full name.
    SubdivisionType type = 3 [(.wix.api.field_exposure) = PRIVATE]; // Subdivision level
    google.protobuf.StringValue type_info = 4 [(.wix.api.field_exposure) = PRIVATE]; // Free text description of subdivision type.
    StandardDetails standard_details = 5 [(.wix.api.field_exposure) = PRIVATE]; // Standard organizations details (e.g. ISO).
}

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

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

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

message VatId {
    option (.wix.api.decomposition_minimum_fields) = {
        field: "id"
        field: "type"
    };
    string id = 1 [(.wix.api.pii) = true]; // 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.decomposition_minimum_fields) = {
        field: "latitude"
        field: "longitude"
    };
    google.protobuf.DoubleValue latitude = 1 [(.wix.api.pii) = true]; // Address latitude.
    google.protobuf.DoubleValue longitude = 2 [(.wix.api.pii) = true]; // Address longitude.
}
