
import React from 'react';

// ============== Types ==============

export type DataType = 'string' | 'number' | 'boolean' | 'date';

export type ColumnType = 'input' | 'output' | 'annotation';

export type HitPolicy = 'UNIQUE' | 'FIRST' | 'PRIORITY' | 'ANY' | 'COLLECT' | 'RULE ORDER' | 'OUTPUT ORDER';

export interface ColumnDefinition {
  id: string;
  label: string;
  variableName?: string;
  type: ColumnType;
  dataType: DataType;
  width?: number;
}

export interface Rule {
  id: string;
  cells: Record<string, string>;
}

export interface DmnModel {
  id: string;
  name: string;
  hitPolicy: HitPolicy;
  columns: ColumnDefinition[];
  rules: Rule[];
}

// ============== Editor Props ==============

export interface EditorToolSpec {
  name: string;
  description: string;
  parameters: Record<string, unknown>;
}
export interface EditorToolResult {
  ok: boolean;
  result?: unknown;
  rejected?: boolean;
  reason?: string;
}
export interface EditorAiCapability {
  kind: string;
  targetId?: string;
  guidelines: string;
  tools: EditorToolSpec[];
  invoke: (toolName: string, args: Record<string, unknown>) => Promise<EditorToolResult>;
}

export interface EditorProps {
  /** Initial DMN XML string to load. If not provided, loads a sample decision table. */
  initialXml?: string;
  /** Callback when save button is clicked. Receives the DMN XML string. */
  onSave?: (xml: string) => void;
  /** Callback when back button is clicked. */
  onBack?: () => void;
  /** Theme mode. If provided, the editor uses this theme and hides the theme toggle. */
  theme?: 'light' | 'dark';
  /** Publishes the editor's AI capability to the host (null on unmount / when not editing). */
  onAiCapabilityReady?: (cap: EditorAiCapability | null) => void;
}

// ============== XML Utilities ==============

/** Default DMN XML template used when no initialXml is provided */
export const INITIAL_DMN_XML: string;

/** Parse a DMN XML string into a DmnModel object */
export function parseDmnXml(xmlStr: string): DmnModel;

/** Generate a DMN XML string from a DmnModel object */
export function generateDmnXml(model: DmnModel): string;

// ============== AI Capability ==============

/** Builds the editor's AI capability over a live model + viewport/selection accessors. */
export function createDmnAiCapability(access: unknown): EditorAiCapability;

// ============== Components ==============

/** Main DMN Editor component */
export const Editor: React.FC<EditorProps>;

/** Alias for Editor */
export const DmnEditor: React.FC<EditorProps>;

export default Editor;
