import type { Node } from "./core";

type DatasetSelectorBase = { versionId?: string; splits?: string[] };

/**
 * A dataset can be identified by its datasetId, datasetName, or datasetVersionId
 */
export type DatasetSelector =
  | (DatasetSelectorBase & { datasetId: string })
  | (DatasetSelectorBase & { datasetName: string });

/**
 * Overview information about a dataset
 */
export interface DatasetInfo extends Node {
  name: string;
  description?: string | null;
  metadata?: Record<string, unknown>;
}

/**
 * Information about a dataset version
 */
export interface DatasetVersionInfo extends Node {
  description?: string | null;
  metadata?: Record<string, unknown>;
  createdAt: Date;
}

/**
 * A dataset's examples
 */
export interface DatasetExamples {
  examples: ExampleWithId[];
  /**
   * The version ID of the dataset examples
   */
  versionId: string;
}

/**
 * An example is a record to feed into an AI task
 */
export interface Example {
  input: Record<string, unknown>;
  output?: Record<string, unknown> | null;
  metadata?: Record<string, unknown> | null;
  /**
   * Split assignment for this example. Can be:
   * - A single string for one split: "train"
   * - An array of strings for multiple splits: ["train", "easy"]
   * - null for no split assignment
   */
  splits?: string | string[] | null;
  /**
   * OpenTelemetry span ID to link this example back to its source span.
   * When provided, the dataset example will be associated with the span
   * in the Phoenix UI, enabling traceability from datasets back to traces.
   */
  spanId?: string | null;
  /**
   * Optional user-provided ID for this example.
   * If not provided, the server will generate an ID.
   */
  id?: string | null;
}

/**
 * An example that has been synced to the server
 */
export interface ExampleWithId extends Example {
  /** The user-provided or server-generated ID for this example. */
  id: string;
  /** Server-generated node ID for this example. */
  nodeId: string;
  updatedAt: Date;
}

/**
 * A dataset is a collection of examples for an AI task
 */
export interface Dataset extends DatasetInfo, DatasetExamples, Node {}

/**
 * A dataset with its version information
 */
export interface DatasetWithVersion extends Dataset {
  versionInfo: DatasetVersionInfo;
}
