import { NodeConnectionTypes, type INodeDataBaseSchema, type INodeType } from '../../Interface'

import Setter from './setter.vue'
import { getNodeDescription, getNodeDisplayName } from '@/nodes/i18n'

export type ScheduleFrequency = 'hourly' | 'daily' | 'weekly' | 'monthly'
export type ScheduleMode = 'visual' | 'cron'
export type ScheduleWeekday = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat'

export interface ScheduleVisualConfig {
	minute: number
	time: string
	weekdays: ScheduleWeekday[]
	monthly_days: Array<number | 'last'>
}

export type ScheduleData = INodeDataBaseSchema & {
	frequency: ScheduleFrequency
	mode: ScheduleMode
	timezone?: string
	cron_expression: string
	visual_config: ScheduleVisualConfig
}

export const triggerScheduleNode: INodeType = {
	version: ['1'],
	displayName: getNodeDisplayName('trigger-schedule'),
	name: 'trigger-schedule',
	description: getNodeDescription('trigger-schedule'),
	group: 'start',
	icon: 'lucide:clock',
	iconColor: '#875bf7',
	Setter,
	inputs: [],
	outputs: [NodeConnectionTypes.main],
	schema: {
		appAgentId: '',
		parentId: '',
		position: {
			x: 20,
			y: 30
		},
		width: 96,
		height: 96,
		selected: false,
		nodeType: 'trigger-schedule',
		zIndex: 1,
		data: {
			title: getNodeDisplayName('trigger-schedule'),
			type: 'trigger-schedule',
			isInIteration: false,
			iteration_id: '',
			isInLoop: false,
			loop_id: '',
			variables: [],
			retry_config: {
				max_retries: 3,
				retry_enabled: false,
				retry_interval: 100
			},
			error_strategy: 'none',
			fail_branch_node_id: '',
			default_value: [],
			output_can_alter: false,
			outputs: [],
			frequency: 'daily',
			mode: 'visual',
			timezone: '',
			cron_expression: '0 0 0 * * ? *',
			visual_config: {
				minute: 0,
				time: '00:00',
				weekdays: ['sun'],
				monthly_days: [1]
			}
		}
	}
}
