import type {
  EnvironmentType,
  MachinePreset,
  PlacementTag,
  RunAnnotations,
} from "@trigger.dev/core/v3";

export interface WorkloadManagerOptions {
  workloadApiProtocol: "http" | "https";
  workloadApiDomain?: string; // If unset, will use orchestrator-specific default
  workloadApiPort: number;
  warmStartUrl?: string;
  metadataUrl?: string;
  imagePullSecrets?: string[];
  heartbeatIntervalSeconds?: number;
  snapshotPollIntervalSeconds?: number;
  additionalEnvVars?: Record<string, string>;
  dockerAutoremove?: boolean;
}

export interface WorkloadManager {
  create: (opts: WorkloadManagerCreateOptions) => Promise<unknown>;
}

export interface WorkloadManagerCreateOptions {
  image: string;
  machine: MachinePreset;
  version: string;
  nextAttemptNumber?: number;
  dequeuedAt: Date;
  placementTags?: PlacementTag[];
  // Timing context (populated by supervisor handler, included in wide event)
  dequeueResponseMs?: number;
  pollingIntervalMs?: number;
  warmStartCheckMs?: number;
  // identifiers
  envId: string;
  envType: EnvironmentType;
  orgId: string;
  projectId: string;
  deploymentFriendlyId: string;
  deploymentVersion: string;
  runId: string;
  runFriendlyId: string;
  snapshotId: string;
  snapshotFriendlyId: string;
  // Trace context for OTel span emission (W3C format: { traceparent: "00-...", tracestate?: "..." })
  traceContext?: Record<string, unknown>;
  annotations?: RunAnnotations;
  // private networking
  hasPrivateLink?: boolean;
}
