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

export type BasicDatasetData = INodeDataBaseSchema & {
	path: string
	group: string
	key: string
}

export const basicDatasetNode: INodeType = {
	version: ['1'],
	displayName: getNodeDisplayName('basic-dataset'),
	name: 'basic-dataset',
	Setter,
	description: getNodeDescription('basic-dataset'),
	group: 'data',
	icon: 'lucide:database',
	iconColor: '#12b76a',
	inputs: [NodeConnectionTypes.main],
	outputs: [NodeConnectionTypes.main],
	validate: (data: BasicDatasetData) => {
		return data?.path?.trim() ? false : i18n.t('pages.basicDatasetSetter.pathRequired')
	},
	getSubtitle: (node: BasicDatasetData | { data?: BasicDatasetData }) => {
		const data = node?.data || node
		if (data?.key?.trim()) return `key: ${data.key}`
		if (data?.group?.trim()) return `group: ${data.group}`
		return data?.path || ''
	},
	schema: {
		appAgentId: '',
		parentId: '',
		position: {
			x: 20,
			y: 30
		},
		width: 96,
		height: 96,
		selected: false,
		nodeType: 'basic-dataset',
		zIndex: 1,
		data: {
			path: '',
			group: '',
			key: ''
		}
	}
}
