syntax = "proto3";

package nominal.usage_tracking.v1;

import "buf/validate/validate.proto";
import "google/api/annotations.proto";
import "nominal/protos/gen/v1/alias.proto";

option java_multiple_files = true;
option java_package = "io.nominal.usage_tracking.v1";

// The type of resource involved in a usage tracking event.
// buf:lint:ignore ENUM_VALUE_PREFIX
enum ResourceType {
  RESOURCE_TYPE_UNSPECIFIED = 0;
  RESOURCE_TYPE_WORKBOOK = 1;
  RESOURCE_TYPE_CHECKLIST = 2;
  RESOURCE_TYPE_PROCEDURE = 3;
}

// A resource-opened event.
message ResourceOpenedEvent {
  // The type of resource that was opened.
  ResourceType resource_type = 1 [(buf.validate.field).enum = {
    not_in: [0]
  }];
  // The RID of the resource that was opened.
  string rid = 2 [
    (nominal.gen.v1.alias) = {java_name: "com.palantir.ri.ResourceIdentifier"},
    (buf.validate.field) = {required: true}
  ];
  // Whether the current user is the creator of the resource.
  bool is_creator = 3;
}

// Request to track a usage event.
message TrackEventRequest {
  // The workspace in which the event occurred.
  string workspace_rid = 1 [
    (nominal.gen.v1.alias) = {java_name: "io.nominal.api.rids.WorkspaceRid"},
    (buf.validate.field) = {required: true}
  ];

  // The event to track. Exactly one must be set.
  oneof event {
    option (buf.validate.oneof) = {required: true};

    ResourceOpenedEvent resource_opened = 2;
  }
}

// Response for tracking a usage event.
message TrackEventResponse {}

// Service for tracking usage events from the frontend.
service UsageTrackingService {
  // Tracks a usage event. Accepts an event with associated metadata and publishes
  // it as an internal usage tracking metric.
  rpc TrackEvent(TrackEventRequest) returns (TrackEventResponse) {
    option (google.api.http) = {
      post: "/usage-tracking/v1/events"
      body: "*"
    };
  }
}
