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

type CaseType = {
	id: string
	logical_operator: 'and' | 'or'
	conditions: ConditionType[]
}

export type ConditionData = INodeDataBaseSchema & {
	cases: CaseType[]
}

export const conditionNode: INodeType = {
	version: ['1'],
	displayName: getNodeDisplayName('if-else'),
	name: 'if-else',
	Setter,
	description: getNodeDescription('if-else'),
	group: 'logic',
	icon: 'lucide:trending-up-down',
	iconColor: '#06aed4',
	inputs: [NodeConnectionTypes.main],
	outputs: (data: ConditionData) => {
		const cases = data?.cases || []
		const ports = cases.map((condition, index) => {
			return {
				id: condition.id,
				label: getConditionPortLabel(index),
				type: 'port'
			}
		})

		ports.push({
			id: data?.id ? `${data.id}-source` : 'source',
			label: 'ELSE',
			type: 'port'
		})
		return ports
	},
	schema: {
		appAgentId: '',
		parentId: '',
		position: {
			x: 20,
			y: 30
		},
		width: 96,
		height: 96,
		selected: false,
		nodeType: 'if-else',
		zIndex: 1,
		data: {}
	}
}
