syntax = "proto3";

package devvit.data.api.admin.v1alpha;

import "devvit/data/api/admin/v1alpha/organization.proto";
import "devvit/data/api/admin/v1alpha/user.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.snooguts.net/reddit/devplatform-api/go/grpc/devvit/data/api/admin/v1alpha";

enum AuditLogEventType {
  DATA_SUBSCRIPTION_CREATE = 0;
  DATA_SUBSCRIPTION_UPDATE = 1;
  DATA_SUBSCRIPTION_DELETE = 2;
  DATA_TOKEN_CREATE = 3;
  DATA_TOKEN_REVOKE = 4;
  ORGANIZATION_DELETE = 5;
  ORGANIZATION_UPDATE = 6;
  ORGANIZATION_CREATE = 7;
  USER_CREATE = 8;
  USER_DELETE = 9;
}

message AuditLogEvent {
  string id = 1; // unique identifier for the event
  google.protobuf.Timestamp created_at = 2; // when the event was created
  string user_id = 3; // t2_ id of the user who performed the action
  AuditLogEventType type = 4; // type of the event
  string organization_id = 5; // id of the organization the event is associated with
  oneof payload {
    DataTokenCreateAuditLogEventPayload data_token_create_payload = 6;
    DataTokenRevokeAuditLogEventPayload data_token_revoke_payload = 7;
    DataSubscriptionCreateAuditLogEventPayload data_subscription_create_payload = 8;
    DataSubscriptionUpdateAuditLogEventPayload data_subscription_update_payload = 9;
    DataSubscriptionDeleteAuditLogEventPayload data_subscription_delete_payload = 10;
    OrganizationDeleteAuditLogEventPayload organization_delete_payload = 11;
    OrganizationUpdateAuditLogEventPayload organization_update_payload = 12;
    OrganizationCreateAuditLogEventPayload organization_create_payload = 13;
    UserCreateAuditLogEventPayload user_create_payload = 14;
    UserDeleteAuditLogEventPayload user_delete_payload = 15;
  }
}

message DataTokenCreateAuditLogEventPayload {
  string token_id = 1; // id of the data token that was created
  google.protobuf.Timestamp expiration = 2; // expiration date of the data token
}

message DataTokenRevokeAuditLogEventPayload {
  string token_id = 1; // id of the data token that was revoked
}

message DataSubscriptionCreateAuditLogEventPayload {
  string subscription_id = 1;
}

message DataSubscriptionUpdateAuditLogEventPayload {
  string subscription_id = 1;
}

message DataSubscriptionDeleteAuditLogEventPayload {
  string subscription_id = 1;
}

message OrganizationCreateAuditLogEventPayload {
  Organization organization = 1;
}

message OrganizationDeleteAuditLogEventPayload {
  Organization organization = 1;
}

message OrganizationUpdateAuditLogEventPayload {
  Organization organization = 1;
}

message GetAuditLogEventsByOrganizationNameRequest {
  string organization_name = 1;
}

message GetAuditLogEventsByOrganizationNameResponse {
  repeated AuditLogEvent events = 1;
}

message CreateAuditLogEventRequest {
  AuditLogEvent event = 1;
}

message CreateAuditLogEventResponse {}

message UserCreateAuditLogEventPayload {
  User user = 1;
}

message UserDeleteAuditLogEventPayload {
  User user = 1;
}
