syntax = "proto3";

package audit.v1;

option go_package = "git.dcentral.systems/toolz/goplt/api/proto/generated/audit/v1;auditv1";

// AuditService provides audit logging operations.
service AuditService {
  // Record records an audit log entry.
  rpc Record(RecordRequest) returns (RecordResponse);
  
  // Query queries audit logs based on filters.
  rpc Query(QueryRequest) returns (QueryResponse);
}

// AuditLogEntry represents an audit log entry.
message AuditLogEntry {
  string user_id = 1;
  string action = 2; // e.g., "user.create", "user.update"
  string resource = 3; // e.g., "user", "role"
  string resource_id = 4;
  string ip_address = 5;
  string user_agent = 6;
  map<string, string> metadata = 7;
  int64 timestamp = 8;
}

// RecordRequest contains an audit log entry to record.
message RecordRequest {
  AuditLogEntry entry = 1;
}

// RecordResponse indicates success.
message RecordResponse {
  bool success = 1;
  string id = 2; // Audit log entry ID
}

// QueryRequest contains filters for querying audit logs.
message QueryRequest {
  optional string user_id = 1;
  optional string action = 2;
  optional string resource = 3;
  optional string resource_id = 4;
  optional int64 start_time = 5;
  optional int64 end_time = 6;
  int32 limit = 7; // Max number of results
  int32 offset = 8; // Pagination offset
}

// QueryResponse contains audit log entries.
message QueryResponse {
  repeated AuditLogEntry entries = 1;
  int32 total = 2; // Total number of matching entries
}

