syntax = "proto3";

package user;

option go_package = "user";

import "eventbus/change.proto";
import "eventbus/owner.proto";

// UserUpdate is triggered on various user/profile change actions.
//
// Other than the 'user_id' field which is always included, all the
// other fields are optional and not necessarily included in all events.
// Clients should anticipate this depending on user actions and not rely
// on getting the entire range of values.
//
// Various PII fields are currently omitted, though that they have changed
// is signaled using the 'Change' type. It is designed in such a way that
// we may be able to upgrade them to encrypted fields in the future.
message UserUpdate {
  option (eventbus.owner.ldap_group) = "team-identity";
  string user_id = 1;
  // The alphanumeric login name of the user.
  eventbus.change.StringChange login = 2;
  // Supplemental field for login describing the type of login change.
  LoginChangeType login_change_type = 12;
  // Display Name is the stylized version of the login name (may contain localized characters).
  eventbus.change.StringChange display_name = 3;
  // Birthday change can be signaled, data currently omitted for PII.
  eventbus.change.Change birthday = 4;
  // Email address change can be signaled, data currently omitted for PII.
  eventbus.change.Change email = 5;
  // Phone number change can be signaled, data currently omitted for PII.
  eventbus.change.Change phone_number = 11;
  // Language is an ISO-639-1 two-letter language code e.g. 'en'
  eventbus.change.StringChange language = 6;
  // The user's own set description. May be multi-line.
  eventbus.change.StringChange description = 7;
  // Each image change key is a size code e.g 320x400.
  map<string, ImageChange> profile_image = 8;
  map<string, ImageChange> profile_banner = 9;
  map<string, ImageChange> channel_offline_image = 10;
}

// Image denotes one of the user's image choices.
message Image {
  uint32 height = 1;
  uint32 width = 2;
  string url = 3;
}

// ImageChange represents a changed image and follows the 'change.proto' scheme.
message ImageChange {
  bool updated = 1;
  Image value = 2;
  bool has_old_value = 3;
  Image old_value = 4;
}

// LoginChangeType contains the different types of a login change.
enum LoginChangeType {
  // Indicates no login change or an unknown type.
  LOGIN_CHANGE_TYPE_INVALID = 0;
  // Indicates a standard login change.
  LOGIN_CHANGE_TYPE_NORMAL = 1;
  // Indicates that user's login has been changed because of a username reset.
  LOGIN_CHANGE_TYPE_RESET = 2;
}
