import {
	IExecuteFunctions,
	INodeExecutionData,
	INodeType,
	INodeTypeDescription,
	NodeOperationError,
} from 'n8n-workflow';

export class ProxMoxMinimal implements INodeType {
	description: INodeTypeDescription = {
		displayName: 'ProxMox VE Minimal',
		name: 'proxMoxMinimal',
		icon: 'file:ProxMox.svg',
		group: ['transform'],
		version: 1,
		subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
		description: 'Minimal ProxMox node for debugging',
		defaults: {
			name: 'ProxMox VE Minimal',
		},
		inputs: ['main'],
		outputs: ['main'],
		credentials: [
			{
				name: 'proxMoxApi',
				required: true,
			},
		],
		properties: [
			{
				displayName: 'Resource',
				name: 'resource',
				type: 'options',
				noDataExpression: true,
				options: [
					{
						name: 'Virtual Machine',
						value: 'vm',
						description: 'Manage virtual machines',
					},
				],
				default: 'vm',
				required: true,
			},
			{
				displayName: 'Operation',
				name: 'operation',
				type: 'options',
				noDataExpression: true,
				displayOptions: {
					show: {
						resource: ['vm'],
					},
				},
				options: [
					{
						name: 'Get All',
						value: 'getAll',
						description: 'Get all virtual machines',
						action: 'Get all virtual machines',
					},
				],
				default: 'getAll',
			},
		],
	};

	async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
		console.log('\n\n========== PROXMOX MINIMAL NODE EXECUTION STARTED ==========');

		try {
			const items = this.getInputData();
			const returnData: INodeExecutionData[] = [];

			console.log('Getting parameters...');
			const resource = this.getNodeParameter('resource', 0) as string;
			const operation = this.getNodeParameter('operation', 0) as string;

			console.log('Parameters retrieved:', { resource, operation });

			// Simple test data
			returnData.push({
				json: {
					test: 'ProxMox minimal node working',
					resource,
					operation,
				},
			});

			console.log('========== PROXMOX MINIMAL NODE EXECUTION COMPLETED ==========\n\n');
			return [returnData];
		} catch (error) {
			console.log('ERROR in minimal node execution:');
			console.log(error);
			throw error;
		}
	}
}
