import type { DecisionPointPayload, DecisionType, JsonValue } from "./models.js";
import { generateId, nowISO } from "./models.js";

export interface CreateDecisionInput {
  type: DecisionType;
  chosen: JsonValue;
  alternatives?: JsonValue[];
  reasoning?: string;
  contextSnapshot?: JsonValue;
  durationMs?: number;
  costUsd?: number;
  parentSpanId?: string;
  timestamp?: string;
}

export function createDecision(input: CreateDecisionInput): DecisionPointPayload {
  return {
    id: generateId(),
    type: input.type,
    chosen: input.chosen,
    alternatives: input.alternatives ?? [],
    reasoning: input.reasoning,
    contextSnapshot: input.contextSnapshot,
    durationMs: input.durationMs,
    costUsd: input.costUsd,
    parentSpanId: input.parentSpanId,
    timestamp: input.timestamp ?? nowISO(),
  };
}
