import { BaseRecord } from '@easy-coder/sdk/data';
import { VariableDefine } from '@easy-coder/sdk/variable';

export type WithNextNodeName<T extends Record<string, any>> = T & {
    nextNodeName?: string;
    input?: Record<string, VariableDefine.Desc>;
};
export interface FlowResult {
    code: string;
    desc: VariableDefine.Desc;
}
export interface Flow<P extends Record<string, any> = any> extends BaseRecord {
    name: string;
    apiName: string;
    label: string;
    type: 'timing' | 'webhook' | 'recordDel' | 'recordCreateOrUpdate' | 'pageEvent';
    schemaPath: string;
    draftPath: string;
    description?: string;
    isActive?: boolean;
    isComplete?: boolean;
    recordDetailLog?: boolean;
    params?: WithNextNodeName<P>;
    result?: Record<string, FlowResult>;
    customVar?: Record<string, {
        defaultValue?: any;
        desc: VariableDefine.Desc;
    }>;
}
export interface FlowNode<P = any> {
    name: string;
    nextNodeName?: string;
    label: string;
    type: 'function' | 'subFlow' | 'http' | 'delay' | 'varAssign' | 'createData' | 'findCount' | 'findOne' | 'findData' | 'updateData' | 'delData' | 'condition' | 'parallel' | 'conditionLoop' | 'listLoop';
    params?: P;
    result?: Record<string, VariableDefine.Desc>;
}
export interface WithNodesFlow<P extends Record<string, any> = any> extends Flow<P> {
    nodes?: Record<string, FlowNode>;
}
export interface FlowLog<I = any, O = any> extends Pick<BaseRecord, '_id' | '_created_at' | '_created_by'> {
    flow: number;
    status: 'wait' | 'inprogress' | 'fail' | 'stop' | 'success';
    msg?: string;
    input?: I;
    log?: string;
    output?: O;
}
export interface ParseFlowLog<I = any, O = any> extends Omit<FlowLog<I, O>, 'log'> {
    log?: FlowNodeLog[];
}
export interface FlowNodeSingleLog<T = any> {
    level: 'info' | 'error';
    data: T;
}
export interface FlowNodeLog {
    nodeName: string;
    id: string;
    parentId?: string;
    logs: FlowNodeSingleLog[];
}
