export interface DelegateStep {
  readonly type: "delegate";
  readonly task: string;
  readonly from_agent: string;
  readonly description: string;
  readonly optional: boolean;
  readonly max_retries: number;
  readonly depends_on?: readonly string[];
}

export interface GateStep {
  readonly type: "gate";
  readonly gate_kind: string;
  readonly description: string;
  readonly depends_on?: readonly string[];
}

export type WorkflowStep = DelegateStep | GateStep;

export interface WorkflowContract {
  readonly id: string;
  readonly description: string;
  readonly trigger: string;
  readonly entry_conditions: readonly string[];
  readonly steps: readonly WorkflowStep[];
}

{{#each workflowEntries}}
export const {{varName}}: WorkflowContract = {
  id: "{{id}}",
  description: {{{json description}}},
  trigger: {{{json trigger}}},
  entry_conditions: {{{json entry_conditions}}},
  steps: [
{{#each steps}}
{{#if (eq type "delegate")}}
    {
      type: "delegate",
      task: "{{task}}",
      from_agent: "{{from_agent}}",
      description: {{{json description}}},
      optional: {{optional}},
      max_retries: {{max_retries}},
{{#if (hasDependsOn this)}}
      depends_on: {{{json depends_on}}},
{{/if}}
    },
{{/if}}
{{#if (eq type "gate")}}
    {
      type: "gate",
      gate_kind: "{{gate_kind}}",
      description: {{{json description}}},
{{#if (hasDependsOn this)}}
      depends_on: {{{json depends_on}}},
{{/if}}
    },
{{/if}}
{{/each}}
  ],
};

{{/each}}
export const workflowRegistry: Record<string, WorkflowContract> = {
{{#each workflowEntries}}
  "{{id}}": {{varName}},
{{/each}}
};
