syntax = "proto3";

// If you make any changes make sure you run: make regenerate-proto

package gitlab.agent.workspaces.server;

option go_package = "gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v18/internal/module/workspaces/server";

import "google/protobuf/timestamp.proto";
import "buf/validate/validate.proto";

// User represents an authenticated user.
message User {
  int64 id = 1 [json_name = "id", (buf.validate.field).int64.gt = 0];
}

// Workspace represents the workspace that is being requested by the user.
message Workspace {
  int64 id = 1 [json_name = "id", (buf.validate.field).int64.gt = 0];
  // Maximum value for a network port is an unsigned 16-bit integer - 65535 .
  uint32 port = 2 [json_name = "port", (buf.validate.field).uint32.lte = 65535];
}

// OAuthStateParam represents data encoded in the OAuth state query parameter.
message OAuthStateParam {
  string nonce = 1 [json_name = "nonce", (buf.validate.field).string.min_bytes = 1];
  string original_url = 2 [json_name = "original_url", (buf.validate.field).string.min_bytes = 1]; // JSON encoded URL
  google.protobuf.Timestamp created_at = 3 [json_name = "created_at", (buf.validate.field).timestamp.gt = {}];
}

// OAuthState represents temporary state during OAuth flow.
message OAuthState {
  google.protobuf.Timestamp created_at = 1 [json_name = "created_at", (buf.validate.field).timestamp.gt = {}];
  string original_url = 2 [json_name = "original_url", (buf.validate.field).string.min_bytes = 1]; // JSON encoded URL
  string code_verifier = 3 [json_name = "code_verifier", (buf.validate.field).string.min_bytes = 1];
  string state_value = 4 [json_name = "state_value", (buf.validate.field).string.min_bytes = 1];
}

// TransferError represents errors during oauth callback which need to be transferred to the original workspace URL.
message TransferError {
  string original_url = 1 [json_name = "original_url", (buf.validate.field).string.min_bytes = 1]; // JSON encoded URL
  // HttpStatusCode is the http status to be sent back in the response.
  uint32 http_status_code = 2 [json_name = "http_status_code"];
  // Message is the message to be sent back in the response.
  string message = 3 [json_name = "message", (buf.validate.field).string.min_bytes = 1];
}

// TransferToken represents temporary tokens for user session transfer.
message TransferToken {
  google.protobuf.Timestamp created_at = 1 [json_name = "created_at", (buf.validate.field).timestamp.gt = {}];
  string original_url = 2 [json_name = "original_url", (buf.validate.field).string.min_bytes = 1]; // JSON encoded URL
  User user = 3 [json_name = "user", (buf.validate.field).required = true];
  Workspace workspace = 4 [json_name = "workspace", (buf.validate.field).required = true];
}

// UserSession represents an authenticated and authorized user session.
message UserSession {
  google.protobuf.Timestamp created_at = 1 [json_name = "created_at", (buf.validate.field).timestamp.gt = {}];
  string host = 2 [json_name = "host", (buf.validate.field).string.min_bytes = 1];
  User user = 3 [json_name = "user", (buf.validate.field).required = true];
  Workspace workspace = 4 [json_name = "workspace", (buf.validate.field).required = true];
}
