import { schemas } from '../api/schema.gen';
import { z } from 'zod';

// Re-export backend types from generated schema
export type {
    TaskStatus,
    TaskType,
    TaskNode,
    TaskDependency,
    WorkflowDag,
} from '../api/schema.gen';

export type WorkflowEvent = z.infer<typeof schemas.WorkflowEvent>;

import { TaskStatus } from '../api/schema.gen';

// Frontend connection states that precede the actual workflow
// Defined as an object to emulate enum behavior for consistency with schema.gen.ts
export const ConnectionStatus = {
    Idle: 'Idle',
    Connecting: 'Connecting'
} as const;

export type ConnectionStatus = typeof ConnectionStatus[keyof typeof ConnectionStatus];

/**
 * Combined status type: 
 * - ConnectionStatus (Frontend only)
 * - TaskStatus (Backend Single Source of Truth via schema.gen.ts)
 * 
 * We reuse TaskStatus here because WorkflowStatus is not currently exported in schema.gen.ts,
 * and TaskStatus shares the same semantic values (Running, Completed, Failed) required for the UI.
 */
export type WorkflowStatus = ConnectionStatus | TaskStatus;

// Frontend-only state wrapper
export interface TaskState {
    status: TaskStatus;
    message?: string; // Last log message
    progress?: number; // 0-100
    logs: string[];   // Full log history
    content?: string; // Streaming content (Markdown)
    result?: unknown;     // Structured result
    // Context Inspector
    inputCommit?: string;
    outputCommit?: string;
    metadata?: import('../api/schema.gen').TaskMetadata; // (New) Metadata from backend
}
