import type { VarType } from '@/types/var'
import { NodeConnectionTypes, type INodeType, type INodeDataBaseSchema } from '../../Interface'
import Setter from './setter.vue'
import { getNodeDescription, getNodeDisplayName } from '@/nodes/i18n'

export type LoopData = INodeDataBaseSchema & {
	loop_count: number
	break_conditions: Array<{
		comparison_operator:
			| 'contains'
			| 'not_contains'
			| 'start_with'
			| 'end_with'
			| 'is'
			| 'is_not'
			| 'empty'
			| 'not_empty'
			| '='
			| '!='
			| '>'
			| '<'
			| '≥'
			| '≤'
			| 'all_of'
		left_value: string
		right_value: string
		varType: VarType
	}>
	logical_operator: 'and' | 'or'
	start_node_id: string
	error_handle_mode: 'terminated' | 'continue-on-error' | 'remove-abnormal-output'
}

export const loopNode: INodeType = {
	version: ['1'],
	displayName: getNodeDisplayName('loop'),
	name: 'loop',
	Setter,
	description: getNodeDescription('loop'),
	group: 'logic',
	icon: 'cuida:loop-outline',
	iconColor: '#06aed4',
	inputs: [NodeConnectionTypes.main],
	outputs: [NodeConnectionTypes.main],
	schema: {
		appAgentId: '',
		parentId: '',
		position: {
			x: 20,
			y: 30
		},
		width: 424,
		height: 244,
		selected: false,
		nodeType: 'loop',
		zIndex: 1,
		data: {}
	}
}
