// Copyright 2026 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

edition = "2024";

package personal_context.proto;

option features.enum_type = CLOSED;
option optimize_for = LITE_RUNTIME;

// Enum defining the supported pContext data types.
enum EntityType {
  UNSPECIFIED = 0;
  ORDER = 1;
  SHIPMENT = 2;
  DRIVERS_LICENSE = 3;
  PASSPORT = 4;
  NATIONAL_ID = 5;
  FLIGHT_RESERVATION = 6;
  VEHICLE = 7;
  KNOWN_TRAVELER_NUMBER = 8;
  SENSITIVE_PII_PRESENCE = 9;
  ENCRYPTED_ENTITY = 10;
}

// This is a mirror of google.protobuf.Duration.
message Duration {
  // Signed seconds of the span of time. Must be from -315,576,000,000
  // to +315,576,000,000 inclusive. Note: these bounds are computed from:
  // 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
  int64 seconds = 1;

  // Signed fractions of a second at nanosecond resolution of the span
  // of time. Durations less than one second are represented with a 0
  // `seconds` field and a positive or negative `nanos` field. For durations
  // of one second or more, a non-zero value for the `nanos` field must be
  // of the same sign as the `seconds` field. Must be from -999,999,999
  // to +999,999,999 inclusive.
  int32 nanos = 2;
}

// Represents a whole or partial calendar date, e.g. a birthday. The time of day
// and time zone are either specified elsewhere or are not significant.
//
// This is a mirror of google.type.Date.
message Date {
  // Year of the date. Must be from 1 to 9999, or 0 to specify a date without
  // a year.
  int32 year = 1;
  // Month of a year. Must be from 1 to 12, or 0 to specify a year without a
  // month and day.
  int32 month = 2;
  // Day of a month. Must be from 1 to 31 and valid for the year and month, or 0
  // to specify a year by itself or a year and month where the day isn't
  // significant.
  int32 day = 3;
}

// Represents civil time (or occasionally physical time).
//
// This is a mirror of google.type.DateTime.
message DateTime {
  // Optional. Year of date. Must be from 1 to 9999, or 0 if specifying a
  // datetime without a year.
  int32 year = 1;
  // Optional. Month of year. Must be from 1 to 12, or 0 if specifying a
  // datetime without a month.
  int32 month = 2;
  // Optional. Day of month. Must be from 1 to 31 and valid for the year and
  // month, or 0 if specifying a datetime without a day.
  int32 day = 3;
  // Optional. Hours of day in 24 hour format. Should be from 0 to 23, defaults
  // to 0 (midnight). An API may choose to allow the value "24:00:00" for
  // scenarios like business closing time.
  int32 hours = 4;
  // Optional. Minutes of hour of day. Must be from 0 to 59, defaults to 0.
  int32 minutes = 5;
  // Optional. Seconds of minutes of the time. Must normally be from 0 to 59,
  // defaults to 0. An API may allow the value 60 if it allows leap-seconds.
  int32 seconds = 6;
  // Optional. Fractions of seconds in nanoseconds. Must be from 0 to
  // 999,999,999, defaults to 0.
  int32 nanos = 7;
  // Optional. Specifies either the UTC offset or the time zone of the DateTime.
  oneof time_offset {
    // UTC offset. Must be whole seconds, between -18 hours and +18 hours.
    // For example, a UTC offset of -4:00 would be represented as
    // { seconds: -14400 }.
    Duration utc_offset = 8;
  }
}

message Entity {
  // Oneof to support different Chrome entity data types.
  oneof entity {
    Order order = 1;
    Shipment shipment = 2;
    DriversLicense drivers_license = 3;
    Passport passport = 4;
    NationalId national_id = 5;
    FlightReservation flight_reservation = 6;
    Vehicle vehicle = 7;
    SensitivePiiPresence sensitive_pii_presence = 11;
    KnownTravelerNumber known_traveler_number = 12;
    // The bytes of an encrypted entity.
    //
    // This should be decrypted by the client using the private key stored in
    // kPersonalContextPrivateKey in
    // components/personal_context/core/personal_context_prefs.h.
    //
    // The decrypted payload is a DecryptedEntity, which may contain a
    // DecryptedPassport or DecryptedDriversLicense as the containing entity.
    bytes encrypted_entity = 13;
  }

  // The source references for the entity.
  repeated SourceReference source_references = 8;

  reserved 9, 10;
}

// Represents a reference to a source of an entity.
message SourceReference {
  oneof source_reference {
    GmailReference gmail = 1;
    PhotosReference photos = 2;
    DriveFile drive = 3;
  }
}

// Represents a reference to a Gmail message.
message GmailReference {
  // URL to the email message.
  string message_url = 1;

  // Subject of the email message.
  string subject = 2;
}

// Represents a reference to a Photos item.
message PhotosReference {
  // The deeplink URL of the photo, album or video in Photos.
  string photos_url = 1;
}

// Represents a reference to a Drive file.
message DriveFile {
  // Name of the Drive file.
  string name = 1;
  // Drive URL of the file.
  string url = 2;
}

// Represents a completed purchase transaction from a retail merchant.
message Order {
  // A unique alphanumeric ID generated by the retail merchant to identify the
  // order.
  string order_id = 1;

  // The unique ID to identify the user's account, typically an email address,
  // under which the order was placed.
  string account = 2;

  // The date when the order was placed.
  Date order_date = 3;

  // The name of the merchant.
  string merchant_name = 4;

  // The domain of the merchant.
  string merchant_domain = 5;

  // The names of the products contained within the order.
  repeated string product_names = 6;
}

// Represents a shipment of physical goods delivered by a courier or
// logistics service.
message Shipment {
  // A unique alphanumeric ID assigned to a shipment by a courier or
  // logistics service.
  string tracking_number = 1;

  // The order ID(s) associated with this shipment.
  repeated string associated_order_ids = 2;

  // The name of the courier or logistics service delivering the shipment.
  string carrier_name = 3;

  // The domain (eTLD+1) of the courier or logistics service.
  string carrier_domain = 4;

  // The date on which the shipment is estimated to be delivered.
  // Deprecated: use ship_date instead.
  Date estimated_delivery_date = 5 [deprecated = true];

  // The zip code of the delivery address.
  string delivery_zip_code = 6;

  // The date on which the shipment was shipped.
  Date ship_date = 7;

  // The name of the merchant.
  string merchant_name = 8;

  // The names of the products in the shipment.
  repeated string product_names = 9;
}

// Represents a government-issued driver's license.
message DriversLicense {
  // The name of the user as it appears on the driver's license.
  string name = 1;

  // The unique identifier number for the driver's license.
  string number = 2;

  // The expiration date of the driver's license.
  Date expiration_date = 3;

  // The issue date of the driver's license.
  Date issue_date = 4;

  // The state or province that issued the driver's license.
  string state = 5;
}

// Represents a government-issued passport.
message Passport {
  // The name of the user as it appears on the passport.
  string name = 1;

  // The unique identifier number for the passport.
  string number = 2;

  // The expiration date of the passport.
  Date expiration_date = 3;

  // The issue date of the passport.
  Date issue_date = 4;

  // The country that issued the passport, normalized as a two-letter country
  // code (ISO 3166-1 alpha-2).
  string issuing_country = 5;
}

// Represents a known traveler number.
message KnownTravelerNumber {
  // The name of the user as it appears on the known traveler number.
  string name = 1;

  // The unique identifier number for the known traveler number.
  string number = 2;
}

// Represents a government-issued national identity document.
message NationalId {
  // The name of the user as it appears on the ID.
  string name = 1;

  // The unique identifier number for the national ID.
  string number = 2;

  // The expiration date of the ID.
  Date expiration_date = 3;

  // The issue date of the ID.
  Date issue_date = 4;

  // The country that issued the ID, normalized as a two-letter country code
  // (ISO 3166-1 alpha-2).
  string issuing_country = 5;
}

// Represents a record of a reserved flight for a passenger.
message FlightReservation {
  // The alphanumeric designation for a specific flight route (e.g., "AA123").
  string flight_number = 1;

  // A unique number issued by an airline or travel agency for the ticket,
  // typically 13 digits.
  string flight_ticket_number = 2;

  // A unique alphanumeric identifier for the booking (also known as Record
  // Locator or PNR).
  string flight_confirmation_code = 3;

  // The name of the person traveling as it appears on the reservation.
  string passenger_name = 4;

  // The name or IATA code of the airport where the flight originates.
  string departure_airport = 5;

  // The name or IATA code of the airport where the flight terminates.
  string arrival_airport = 6;

  // The scheduled date and time of departure.
  DateTime departure_time = 7;

  // The scheduled date and time of arrival.
  DateTime arrival_time = 8;
}

// Represents a motor vehicle.
message Vehicle {
  // The manufacturer of the vehicle.
  string vehicle_make = 1;

  // The specific product name of the vehicle.
  string vehicle_model = 2;

  // The manufacturing year of the vehicle.
  string vehicle_year = 3;

  // The unique 17-character Vehicle Identification Number.
  string vehicle_identification_number = 4;

  // The alphanumeric identifier on the vehicle's license plate.
  string vehicle_license_plate = 5;

  // The state or region that issued the vehicle's license plate.
  string license_plate_region = 6;

  // The country that issued the license plate, normalized to ISO 3166-1
  // alpha-2.
  string license_plate_country = 7;

  // The name of the primary owner of the vehicle.
  string owner_name = 8;
}

// Signals the availability of sensitive PII for the user.
message SensitivePiiPresence {
  // The type of SPII data for which presence is indicated.
  enum Type {
    UNSPECIFIED = 0;
    DRIVERS_LICENSE = 1;
    PASSPORT = 2;
    NATIONAL_ID = 3;
  }

  Type type = 1;
}

message DecryptedEntity {
  reserved 2, 5 to 16;

  repeated DecryptedReference references = 1;

  oneof entity {
    DecryptedPassport passport = 3;
    DecryptedDriversLicense drivers_license = 4;
  }
}

message DecryptedReference {
  reserved 2 to 9, 13 to 21, 23 to 47;

  oneof reference {
    DecryptedGmailMessage gmail_message = 1;
    DecryptedPhotosPhoto photo = 10;
    DecryptedPhotosVideo video = 11;
    DecryptedPhotosAlbum photos_album = 12;
    DecryptedDriveFile drive_file = 22;
  }
}

message DecryptedGmailMessage {
  reserved 1, 3 to 5, 7 to 13;

  // Subject of the message.
  string subject = 2;

  // URL to the email message.
  string message_url = 6;
}

message DecryptedPhotosPhoto {
  reserved 1 to 5, 7 to 11;

  // The deeplink url of the photo.
  string deeplink_url = 6;
}

message DecryptedPhotosVideo {
  reserved 1 to 6, 8 to 12;

  // The deeplink url of the video.
  string deeplink_url = 7;
}

message DecryptedPhotosAlbum {
  reserved 1 to 8, 10 to 14;

  // The deeplink url of the album.
  string deeplink_url = 9;
}

message DecryptedDriveFile {
  reserved 1, 3, 4;

  // Drive file title.
  string name = 2;

  // Drive URL of the file.
  string url = 5;
}

message DecryptedPassport {
  reserved 2 to 4, 9, 10;

  // The name of the user as it appears on the passport.
  string full_name = 1;

  // The unique identifier number for the passport.
  string number = 5;

  // The issue date of the passport.
  Date issue_date = 6;

  // The expiration date of the passport.
  Date expiration_date = 7;

  // The country that issued the passport, normalized as a two-letter country
  // code (ISO 3166-1 alpha-2).
  string issuing_country = 8;
}

message DecryptedDriversLicense {
  reserved 2 to 4;

  // The name of the user as it appears on the driver's license.
  string full_name = 1;

  // The unique identifier number for the driver's license.
  string number = 5;

  // The state or province that issued the driver's license.
  string issuing_region = 6;

  // The issue date of the driver's license.
  Date issue_date = 7;

  // The expiration date of the driver's license.
  Date expiration_date = 8;
}

// Represents the memory data types supported by the Chrome client. This
// includes both local Autofill data types and remote data types (e.g. Gmail,
// Photos, etc.).
enum MemoryDataType {
  MEMORY_DATA_TYPE_UNSPECIFIED = 0;
  MEMORY_DATA_TYPE_NAME_FULL = 1;
  MEMORY_DATA_TYPE_ADDRESS_FULL = 2;
  MEMORY_DATA_TYPE_ADDRESS_STREET_ADDRESS = 3;
  MEMORY_DATA_TYPE_ADDRESS_CITY = 4;
  MEMORY_DATA_TYPE_ADDRESS_STATE = 5;
  MEMORY_DATA_TYPE_ADDRESS_ZIP = 6;
  MEMORY_DATA_TYPE_ADDRESS_COUNTRY = 7;
  MEMORY_DATA_TYPE_PHONE = 8;
  MEMORY_DATA_TYPE_EMAIL = 9;
  MEMORY_DATA_TYPE_COMPANY_NAME = 10;
  MEMORY_DATA_TYPE_IBAN = 11;
  MEMORY_DATA_TYPE_IBAN_NICKNAME = 12;
  MEMORY_DATA_TYPE_VEHICLE = 13;
  MEMORY_DATA_TYPE_VEHICLE_MAKE = 14;
  MEMORY_DATA_TYPE_VEHICLE_MODEL = 15;
  MEMORY_DATA_TYPE_VEHICLE_YEAR = 16;
  MEMORY_DATA_TYPE_VEHICLE_OWNER = 17;
  MEMORY_DATA_TYPE_VEHICLE_PLATE_NUMBER = 18;
  MEMORY_DATA_TYPE_VEHICLE_PLATE_STATE = 19;
  MEMORY_DATA_TYPE_VEHICLE_VIN = 20;
  MEMORY_DATA_TYPE_PASSPORT_FULL = 21;
  MEMORY_DATA_TYPE_PASSPORT_NAME = 22;
  MEMORY_DATA_TYPE_PASSPORT_COUNTRY = 23;
  MEMORY_DATA_TYPE_PASSPORT_NUMBER = 24;
  MEMORY_DATA_TYPE_PASSPORT_ISSUE_DATE = 25;
  MEMORY_DATA_TYPE_PASSPORT_EXPIRATION_DATE = 26;
  MEMORY_DATA_TYPE_FLIGHT_RESERVATION_FULL = 27;
  MEMORY_DATA_TYPE_FLIGHT_RESERVATION_FLIGHT_NUMBER = 28;
  MEMORY_DATA_TYPE_FLIGHT_RESERVATION_TICKET_NUMBER = 29;
  MEMORY_DATA_TYPE_FLIGHT_RESERVATION_CONFIRMATION_CODE = 30;
  MEMORY_DATA_TYPE_FLIGHT_RESERVATION_PASSENGER_NAME = 31;
  MEMORY_DATA_TYPE_FLIGHT_RESERVATION_DEPARTURE_AIRPORT = 32;
  MEMORY_DATA_TYPE_FLIGHT_RESERVATION_ARRIVAL_AIRPORT = 33;
  MEMORY_DATA_TYPE_FLIGHT_RESERVATION_DEPARTURE_DATE = 34;
  MEMORY_DATA_TYPE_FLIGHT_RESERVATION_ARRIVAL_DATE = 35;
  MEMORY_DATA_TYPE_SHIPMENT_FULL = 36;
  MEMORY_DATA_TYPE_SHIPMENT_TRACKING_NUMBER = 37;
  MEMORY_DATA_TYPE_SHIPMENT_ASSOCIATED_ORDER_ID = 38;
  MEMORY_DATA_TYPE_SHIPMENT_DELIVERY_ADDRESS = 39;
  MEMORY_DATA_TYPE_SHIPMENT_DELIVERY_ZIP_CODE = 40;
  MEMORY_DATA_TYPE_SHIPMENT_CARRIER_NAME = 41;
  MEMORY_DATA_TYPE_SHIPMENT_CARRIER_DOMAIN = 42;
  MEMORY_DATA_TYPE_SHIPMENT_ESTIMATED_DELIVERY_DATE = 43;
  MEMORY_DATA_TYPE_SHIPMENT_SHIP_DATE = 76;
  MEMORY_DATA_TYPE_NATIONAL_ID_CARD_FULL = 44;
  MEMORY_DATA_TYPE_NATIONAL_ID_CARD_NAME = 45;
  MEMORY_DATA_TYPE_NATIONAL_ID_CARD_COUNTRY = 46;
  MEMORY_DATA_TYPE_NATIONAL_ID_CARD_NUMBER = 47;
  MEMORY_DATA_TYPE_NATIONAL_ID_CARD_ISSUE_DATE = 48;
  MEMORY_DATA_TYPE_NATIONAL_ID_CARD_EXPIRATION_DATE = 49;
  MEMORY_DATA_TYPE_REDRESS_NUMBER_FULL = 50;
  MEMORY_DATA_TYPE_REDRESS_NUMBER_NAME = 51;
  MEMORY_DATA_TYPE_REDRESS_NUMBER_NUMBER = 52;
  MEMORY_DATA_TYPE_KNOWN_TRAVELER_NUMBER_FULL = 53;
  MEMORY_DATA_TYPE_KNOWN_TRAVELER_NUMBER_NAME = 54;
  MEMORY_DATA_TYPE_KNOWN_TRAVELER_NUMBER_NUMBER = 55;
  MEMORY_DATA_TYPE_KNOWN_TRAVELER_NUMBER_EXPIRATION_DATE = 56;
  MEMORY_DATA_TYPE_DRIVERS_LICENSE_FULL = 57;
  MEMORY_DATA_TYPE_DRIVERS_LICENSE_NAME = 58;
  MEMORY_DATA_TYPE_DRIVERS_LICENSE_STATE = 59;
  MEMORY_DATA_TYPE_DRIVERS_LICENSE_NUMBER = 60;
  MEMORY_DATA_TYPE_DRIVERS_LICENSE_ISSUE_DATE = 61;
  MEMORY_DATA_TYPE_DRIVERS_LICENSE_EXPIRATION_DATE = 62;
  MEMORY_DATA_TYPE_ORDER_FULL = 63;
  MEMORY_DATA_TYPE_ORDER_ID = 64;
  MEMORY_DATA_TYPE_ORDER_ACCOUNT = 65;
  MEMORY_DATA_TYPE_ORDER_DATE = 66;
  MEMORY_DATA_TYPE_ORDER_MERCHANT_NAME = 67;
  MEMORY_DATA_TYPE_ORDER_MERCHANT_DOMAIN = 68;
  MEMORY_DATA_TYPE_ORDER_PRODUCT_NAMES = 69;
  MEMORY_DATA_TYPE_ORDER_GRAND_TOTAL = 70;
  MEMORY_DATA_TYPE_CREDIT_CARD_NUMBER = 71;
  MEMORY_DATA_TYPE_CREDIT_CARD_EXPIRATION_DATE = 72;
  MEMORY_DATA_TYPE_CREDIT_CARD_SECURITY_CODE = 73;
  MEMORY_DATA_TYPE_CREDIT_CARD_NAME_ON_CARD = 74;
  MEMORY_DATA_TYPE_CREDIT_CARD_NICKNAME = 75;
}
