syntax = "proto3";

package confidence.flags.resolver.v1.events;

import "confidence/events/v1/annotations.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";
import "google/api/resource.proto";
import "confidence/flags/resolver/v1/types.proto";

option java_package = "com.spotify.confidence.flags.resolver.v1.events";
option java_outer_classname = "EventsProto";
option java_multiple_files = true;

message ClientInfo {
  string client = 1 [
    (google.api.resource_reference).type = "iam.confidence.dev/Client"
  ];
  string client_credential = 2 [
    (google.api.resource_reference).type = "iam.confidence.dev/ClientCredential"
  ];
  //TODO: client version

  // Information about the SDK used to interact with the API.
  Sdk sdk = 3;
}

message FlagAssigned {
  option (confidence.events.v1.event) = {
    persist: false;
    description: "A flag has been applied";
  };

  string resolve_id = 10;

  ClientInfo client_info = 3;

  repeated AppliedFlag flags = 15;

  message AppliedFlag {
    string flag = 1 [
      (google.api.resource_reference).type = "flags.confidence.dev/Flag"
    ];

    string targeting_key = 2;
    string targeting_key_selector = 3;

    oneof assignment {
      AssignmentInfo assignment_info = 4;
      DefaultAssignment default_assignment = 5;
    }

    string assignment_id = 6;

    string rule = 7 [
      (google.api.resource_reference).type = "flags.confidence.dev/Rule"
    ];

    repeated FallthroughAssignment fallthrough_assignments = 8;
    google.protobuf.Timestamp apply_time = 9;
  }

  message AssignmentInfo {
    string segment = 1 [
      (google.api.resource_reference).type = "flags.confidence.dev/Segment"
    ];
    string variant = 2 [
      (google.api.resource_reference).type = "flags.confidence.dev/FlagVariant"
    ];
  }

  message DefaultAssignment {
    DefaultAssignmentReason reason = 1;
    enum DefaultAssignmentReason {
      DEFAULT_ASSIGNMENT_REASON_UNSPECIFIED = 0;
      NO_SEGMENT_MATCH = 1;
      NO_TREATMENT_MATCH = 2 [deprecated = true];
      FLAG_ARCHIVED = 3;
    }
  }
}

message FallthroughAssignment {
  string rule = 1 [
    (google.api.resource_reference).type = "flags.confidence.dev/Rule"
  ];

  string assignment_id = 2;

  string targeting_key = 3;
  string targeting_key_selector = 4;
}
