import { z } from 'zod';

// 圖定義的 Zod Schema
export const graphSchema = z.object({
  id: z.string().min(1),
  name: z.string().min(1),
  nodes: z.array(z.object({
    id: z.string(),
    type: z.enum(['Input', 'Component', 'Output']),
    componentId: z.string().optional(),
    label: z.string().optional(),
    data: z.record(z.unknown()).optional(),
  })),
  edges: z.array(z.object({
    from: z.string(),
    to: z.string(),
    type: z.enum(['PIPE', 'IF', 'FOREACH', 'CONTINUE', 'IS_A', 'ON_SUCCESS', 'ON_FAIL', 'ON_TRUE', 'ON_FALSE', 'ON_BRANCH', 'ON_CLICK', 'CALLS_SUBFLOW', 'CONTAINS', 'HAS_STYLE', 'HAS_BEHAVIOR']),
    condition: z.string().optional(),
    iterator: z.string().optional(),
    branch: z.string().optional(),   // ON_BRANCH 的具名分支（SDD workflow-discovery 3.11）
  })),
});

export const executeSchema = z.object({
  graph: graphSchema,
  context: z.record(z.unknown()).default({}),
});
