// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Sync protocol datatype extension for autofill.

// If you change or add any fields in this file, update proto_visitors.h and
// potentially proto_enum_conversions.{h, cc}.

syntax = "proto2";

option java_multiple_files = true;
option java_package = "org.chromium.components.sync.protocol";

option optimize_for = LITE_RUNTIME;

package sync_pb;

// Properties of autofill sync objects.

// An AutofillProfile.
message AutofillProfileSpecifics {
  // Represents the validation status of value stored in the AutofillProfile.
  enum VerificationStatus {
    // No verification status assigned.
    VERIFICATION_STATUS_UNSPECIFIED = 0;
    // The value token was parsed from a parent token.
    // For example, the first name was derived by splitting a full name into
    // its components.
    PARSED = 1;
    // Value was built from its subcomponents.
    // For example, the full name was built from the first, middle and last
    // name.
    FORMATTED = 2;
    // The value was observed in a form transmission.
    // For example, the user filled a form that contained at NAME_FULL field.
    // The value of NAME_FULL will be stored as OBSERVED.
    OBSERVED = 3;
    // The user used the autofill settings to verify and store this token.
    // This is currently only applicable to the full name, since users cannot
    // edit individual components of their name.
    USER_VERIFIED = 4;
    // The token was parsed remotely.
    SERVER_PARSED = 5;
  }

  optional string guid = 15;
  optional string origin = 16;
  optional int64 use_count = 22;

  // The time_t value of the last time this profile was used. This
  // value makes sense wrt base::Time::To/FromTimeT, which measures
  // from the Windows epoch.
  optional int64 use_date = 23;

  // A user chosen profile label that is used to identify the profile.
  // The value of the label can be freely chosen by the user. Two possible label
  // values are '$HOME$' or '$WORK$' which have a special meaning.
  optional string profile_label = 62;

  // Contact info name fields.
  repeated string name_honorific = 26;
  repeated string name_first = 2;
  repeated string name_middle = 3;
  repeated string name_last = 4;
  // Sometimes the last name is composed of two names as it is common for
  // Hispanic/Latinx names. In the unstructured representation of the last name,
  // there may be even a conjunction between the first and the second last
  // name. For example, the more-complete version of Pablo Picasso's surname is
  // "Ruiz y Picasso" containing a first last name, a conjunction (the y) and a
  // second last name.
  repeated string name_last_first = 27;
  repeated string name_last_conjunction = 28;
  repeated string name_last_second = 29;
  repeated string name_full = 21;
  // This value contains the combination of the full name and the honorific
  // prefix.
  repeated string name_full_with_honorific = 60;

  // Validation status records for name fields.
  repeated VerificationStatus name_honorific_status = 30;
  repeated VerificationStatus name_first_status = 31;
  repeated VerificationStatus name_middle_status = 32;
  repeated VerificationStatus name_last_status = 33;
  repeated VerificationStatus name_last_first_status = 34;
  repeated VerificationStatus name_last_conjunction_status = 35;
  repeated VerificationStatus name_last_second_status = 36;
  repeated VerificationStatus name_full_status = 37;
  repeated VerificationStatus name_full_with_honorific_status = 61;

  // Contact info additional fields.
  repeated string email_address = 5;
  optional string company_name = 6;

  // Address field.
  // The address_home_line1/2 fields are deprecated and
  // address_home_street_address should be used instead by
  // joining address_home_line1/2 with a newline ("\n").
  // Full deprecation can not be achieved before all sync profiles have been
  // updated with a M86+ client.
  // TODO(crbug/1111740): Remove usages of address_home_line1/2 and mark field
  // as deprecated.
  optional string address_home_line1 = 7;
  optional string address_home_line2 = 8;
  optional string address_home_city = 9;
  optional string address_home_state = 10;
  optional string address_home_zip = 11;
  optional string address_home_country = 12;

  // Additional address fields for i18n.
  optional string address_home_street_address = 17;
  optional string address_home_sorting_code = 18;
  optional string address_home_dependent_locality = 19;
  optional string address_home_language_code = 20;
  optional string address_home_thoroughfare_name = 38;
  optional string address_home_thoroughfare_number = 39;
  optional string address_home_dependent_thoroughfare_name = 40;
  optional string address_home_premise_name = 41;
  optional string address_home_subpremise_name = 42;
  optional string address_home_apt_num = 56;
  optional string address_home_floor = 57;

  // Validation status records for address fields.
  optional VerificationStatus address_home_city_status = 43;
  optional VerificationStatus address_home_state_status = 44;
  optional VerificationStatus address_home_zip_status = 45;
  optional VerificationStatus address_home_country_status = 46;
  optional VerificationStatus address_home_street_address_status = 47;
  optional VerificationStatus address_home_sorting_code_status = 48;
  optional VerificationStatus address_home_dependent_locality_status = 49;
  optional VerificationStatus address_home_language_code_status = 50;
  optional VerificationStatus address_home_thoroughfare_name_status = 51;
  optional VerificationStatus address_home_thoroughfare_number_status = 52;
  optional VerificationStatus address_home_dependent_thoroughfare_name_status =
      53;
  optional VerificationStatus address_home_premise_name_status = 54;
  optional VerificationStatus address_home_subpremise_name_status = 55;
  optional VerificationStatus address_home_apt_num_status = 58;
  optional VerificationStatus address_home_floor_status = 59;

  // Phone.
  repeated string phone_home_whole_number = 13;

  // The state indicates if the profile qualifies to get merged with a
  // profile observed in a form submission. If true, the profile can still be
  // updated silently, but it should not be considered for merges that need to
  // involve user interactions.
  optional bool disallow_settings_visible_updates = 63;

  // Birthdate fields.
  optional int32 birthdate_day = 64;
  optional int32 birthdate_month = 65;
  optional int32 birthdate_year = 66;  // 4 digits.

  // Deprecated.
  optional string deprecated_label = 1 [deprecated = true];
  optional string phone_fax_whole_number = 14 [deprecated = true];
  // The following validity-related fields have only been used in combination
  // with an experimental features that are disabled for all clients and have
  // been removed in M100.
  optional int64 validity_state_bitfield = 24 [deprecated = true];
  optional bool is_client_validity_states_updated = 25 [deprecated = true];
}

message AutofillSpecifics {
  // If any of these 3 fields are present, then all 3 should be, and it implies
  // that this entity represents a classic autofill object.  In this case,
  // none of the autofill++ objects below should be present.
  optional string name = 1;
  optional string value = 2;
  repeated int64 usage_timestamp = 3;

  // An autofill++ profile object.  If present, indicates this entity
  // represents an AutofillProfile exclusively, and no other fields (such as
  // name/value or credit_card) should be present.
  optional AutofillProfileSpecifics profile = 4;

  reserved 5;
  reserved "encrypted_credit_card";
  reserved 6;
  reserved "credit_card";
}

// TODO(crbug.com/1020740): Deprecated, remove this once dependent change is
// done. Use WalletCreditCardCloudTokenData instead.
message CloudTokenData {
  // Last 4-5 digits of the Cloud Primary Account Number (CPAN).
  optional string suffix = 1;

  // CPAN Month number 1-12.
  optional int32 exp_month = 2;

  // CPAN Four-digit year (e.g. 2017).
  optional int32 exp_year = 3;

  // URL of the card art to be displayed for CPAN.
  optional string art_fife_url = 4;

  // Opaque identifier for the cloud token associated with the payment
  // instrument.
  optional string instrument_token = 5;
}

message CardIssuer {
  enum Issuer {
    ISSUER_UNKNOWN = 0;
    // Card where the issuer is Google.
    GOOGLE = 1;
    // Card where the issuer is external.
    EXTERNAL_ISSUER = 2;
  }
  optional Issuer issuer = 1;

  // Uniquely identifies the issuer of the card. This field is required when
  // Issuer is EXTERNAL_ISSUER.
  // Example: capitalone, amex.
  optional string issuer_id = 2;
}

message WalletMaskedCreditCard {
  reserved 9, 14;
  reserved "card_class";

  enum WalletCardStatus {
    VALID = 0;
    EXPIRED = 1;
  }

  enum WalletCardType {
    UNKNOWN = 0;
    AMEX = 1;
    DISCOVER = 2;
    JCB = 3;
    MAESTRO = 4;
    MASTER_CARD = 5;
    SOLO = 6;
    SWITCH = 7;
    VISA = 8;
    UNIONPAY = 9;
    ELO = 10;
  }

  enum VirtualCardEnrollmentState {
    UNSPECIFIED = 0;
    UNENROLLED = 1 [deprecated = true];
    ENROLLED = 2;
    UNENROLLED_AND_NOT_ELIGIBLE = 3;
    UNENROLLED_AND_ELIGIBLE = 4;
  }

  enum VirtualCardEnrollmentType {
    TYPE_UNSPECIFIED = 0;
    ISSUER = 1;
    NETWORK = 2;
  }

  // Server-generated unique ID string. This is opaque to the client.
  // This is the legacy version of |instrument_id|.
  optional string id = 1;

  // What the server thinks of this card.
  optional WalletCardStatus status = 2;

  optional string name_on_card = 3;

  optional WalletCardType type = 4;

  // Last 4 digits of the credit card number.
  optional string last_four = 5;

  // Month number 1-12.
  optional int32 exp_month = 6;

  // Four-digit year (e.g. 2017).
  optional int32 exp_year = 7;

  // The WalletPostalAddress.id of the billing address.
  optional string billing_address_id = 8;

  // Issuing Bank name which is internationalized (e.g. "Chase", "工商银行")
  optional string bank_name = 10;

  // TODO(crbug.com/1020740): Deprecated, remove this once dependent change is
  // done.
  // Use WalletCreditCardCloudTokenData instead. This field will be set if
  // a cloud token is available for the instrument.
  optional CloudTokenData cloud_token_data = 11;

  // The card's nickname, if it exists.
  optional string nickname = 12;

  // Issuer of the card.
  optional CardIssuer card_issuer = 13;

  // Server-generated unique ID. This is opaque to the client.
  // |id| is the legacy version of this.
  optional int64 instrument_id = 15;

  // The state of virtual card enrollment.
  optional VirtualCardEnrollmentState virtual_card_enrollment_state = 16;

  // The URL for the client to fetch the card art image.
  optional string card_art_url = 17;

  // The product description for the card. Used to be shown in the UI.
  optional string product_description = 18;

  // The type of virtual card enrollment. TYPE_UNSPECIFIED indicates that the
  // card is unenrolled.
  optional VirtualCardEnrollmentType virtual_card_enrollment_type = 19;
}

// Different than an AutofillProfile because this represents some known address
// on the server that is pulled down rather than synced between Chromes.
message WalletPostalAddress {
  optional string id = 1;

  optional string recipient_name = 12;
  optional string company_name = 2;

  // This is the street address, of which there may be multiple lines. This
  // corresponds to "address_home_line[1|2] in the AutofillProfileSpecifics
  // message above. In some locales there may be more than two lines.
  repeated string street_address = 3;

  // Also known as "administrative area". This is normally the state or
  // province in most countries.
  optional string address_1 = 4;

  // Also known as "locality". In the US this is the city.
  optional string address_2 = 5;

  // A sub-classification beneath the city, e.g. an inner-city district or
  // suburb. Also known as "dependent_locality"
  optional string address_3 = 6;

  // Used in certain countries. Also known as "sub_dependent_locality".
  optional string address_4 = 7;

  optional string postal_code = 8;

  // Similar to the zipcode column, but used for businesses or organizations
  // that might not be geographically contiguous. The canonical example is
  // CEDEX in France.
  optional string sorting_code = 9;

  optional string country_code = 10;
  optional string language_code = 11;

  // Phone number. The format is unspecified and will be explicitly ignored.
  optional string phone_number = 13;
}

// Contains information about a Payments Customer.
message PaymentsCustomerData {
  // The billable customer ID associated with the account.
  optional string id = 1;
}

// Contains information about the cloud token data of server credit cards.
message WalletCreditCardCloudTokenData {
  // Server-generated ID string for the card this cloud token data is related
  // to. This should match the id in WalletMaskedCreditCard for to fetch the
  // corresponding actual card data. Note this is not unique across all cloud
  // token data, which means one card can have multiple sets of cloud token data
  // with the same masked_card_id.
  optional string masked_card_id = 1;

  // Last 4-5 digits of the Cloud Primary Account Number (CPAN).
  optional string suffix = 2;

  // CPAN Month number 1-12.
  optional int32 exp_month = 3;

  // CPAN Four-digit year (e.g. 2017).
  optional int32 exp_year = 4;

  // URL of the card art to be displayed for CPAN.
  optional string art_fife_url = 5;

  // Opaque identifier for the cloud token.
  optional string instrument_token = 6;
}

message AutofillWalletSpecifics {
  enum WalletInfoType {
    UNKNOWN = 0;
    MASKED_CREDIT_CARD = 1;
    POSTAL_ADDRESS = 2;
    CUSTOMER_DATA = 3;
    CREDIT_CARD_CLOUD_TOKEN_DATA = 4;
  }

  optional WalletInfoType type = 1;

  // This field exists if and only if the "type" field equals to
  // MASKED_CREDIT_CARD.
  optional WalletMaskedCreditCard masked_card = 2;

  // This field exists if and only if the "type" field equals to ADDRESS.
  optional WalletPostalAddress address = 3;

  // This field exists if and only if the "type" field equals to CUSTOMER_DATA.
  optional PaymentsCustomerData customer_data = 4;

  // This field exists if and only if the "type" field equals to
  // CREDIT_CARD_CLOUD_TOKEN_DATA.
  optional WalletCreditCardCloudTokenData cloud_token_data = 5;
}

// Wallet card and address usage information that can be synced.
message WalletMetadataSpecifics {
  enum Type {
    UNKNOWN = 0;
    CARD = 1;
    ADDRESS = 2;
  }

  // The type of the Wallet metadata.
  optional Type type = 1;

  // Base64 encoding of the unique ID string of the corresponding Wallet data.
  // For Wallet cards, this value is server generated and opaque to Chrome.
  // For Wallet addresses, this is a SHA1 hash of the following fields:
  //
  // - First name
  // - Middle name
  // - Last name
  // - Company name
  // - Street address
  // - Dependent locality
  // - City
  // - State
  // - Zip code
  // - Sorting code
  // - Country
  // - Phone number
  // - Language code
  optional string id = 2;

  // The number of times that this Wallet card or address was used.
  optional int64 use_count = 3;

  // The last use date of this Wallet card or address. Measured in microseconds
  // since the Windows epoch (1601).
  optional int64 use_date = 4;

  // The id of the profile/address that represents the billing address of this
  // Wallet card.
  optional string card_billing_address_id = 5;

  // Whether this Wallet address has been converted to a local autofill profile.
  optional bool address_has_converted = 6;
}