// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";

package openshell.datamodel.v1;

import "google/protobuf/struct.proto";
import "sandbox.proto";

// Kubernetes-style metadata shared by top-level OpenShell domain objects.
message ObjectMeta {
  // Stable object ID generated by the gateway.
  string id = 1;
  // Human-readable object name.
  string name = 2;
  // Milliseconds since Unix epoch when the object was created.
  int64 created_at_ms = 3;
  // Key-value labels for filtering and organization.
  map<string, string> labels = 4;
}

// Sandbox model stored by OpenShell.
message Sandbox {
  // OpenShell v0.0.42 moved id/name/created_at_ms under metadata.
  ObjectMeta metadata = 1;
  SandboxSpec spec = 2;
  SandboxStatus status = 3;
  SandboxPhase phase = 4;
  // Currently active policy version (updated when sandbox reports loaded).
  uint32 current_policy_version = 5;
}

// OpenShell-level sandbox spec.
message SandboxSpec {
  string log_level = 1;
  map<string, string> environment = 5;
  SandboxTemplate template = 6;
  // Required sandbox policy configuration.
  openshell.sandbox.v1.SandboxPolicy policy = 7;
  // Provider names to attach to this sandbox.
  repeated string providers = 8;
  // Request NVIDIA GPU resources for this sandbox.
  bool gpu = 9;
  // Optional PCI BDF address or device index when gpu=true.
  string gpu_device = 10;
}

// Sandbox template mapped onto Kubernetes pod template inputs.
message SandboxTemplate {
  string image = 1;
  string runtime_class_name = 2;
  string agent_socket = 3;
  map<string, string> labels = 4;
  map<string, string> annotations = 5;
  map<string, string> environment = 6;
  google.protobuf.Struct resources = 7;
  google.protobuf.Struct volume_claim_templates = 9;
}

// Sandbox status captured from Kubernetes.
message SandboxStatus {
  string sandbox_name = 1;
  string agent_pod = 2;
  string agent_fd = 3;
  string sandbox_fd = 4;
  repeated SandboxCondition conditions = 5;
}

// Sandbox condition mirrors Kubernetes conditions.
message SandboxCondition {
  string type = 1;
  string status = 2;
  string reason = 3;
  string message = 4;
  string last_transition_time = 5;
}

// High-level sandbox lifecycle phase.
enum SandboxPhase {
  SANDBOX_PHASE_UNSPECIFIED = 0;
  SANDBOX_PHASE_PROVISIONING = 1;
  SANDBOX_PHASE_READY = 2;
  SANDBOX_PHASE_ERROR = 3;
  SANDBOX_PHASE_DELETING = 4;
  SANDBOX_PHASE_UNKNOWN = 5;
}

// Provider model stored by OpenShell.
message Provider {
  ObjectMeta metadata = 1;
  // Canonical provider type slug (for example: "claude", "gitlab").
  string type = 2;
  // Secret values used for authentication.
  map<string, string> credentials = 3;
  // Non-secret provider configuration.
  map<string, string> config = 4;
}
