import { INodeProperties } from 'n8n-workflow';

export const switchingOperations: INodeProperties[] = [
	{
		displayName: 'Operation',
		name: 'operation',
		type: 'options',
		noDataExpression: true,
		displayOptions: {
			show: {
				resource: ['switching'],
			},
		},
		options: [
			{
				name: 'List VLANs',
				value: 'listVlans',
				description: 'Get all VLANs',
				action: 'List VLANs',
				routing: {
					request: {
						method: 'GET',
						url: '/resources/vlans',
					},
					output: {
						postReceive: [
							{
								type: 'rootProperty',
								properties: {
									property: 'vlans',
								},
							},
						],
					},
				},
			},
			{
				name: 'Get Device VLANs',
				value: 'getDeviceVlans',
				description: 'Get VLANs for a specific device',
				action: 'Get device VLANs',
				routing: {
					request: {
						method: 'GET',
						url: '=/devices/{{$parameter.deviceId}}/vlans',
					},
					output: {
						postReceive: [
							{
								type: 'rootProperty',
								properties: {
									property: 'vlans',
								},
							},
						],
					},
				},
			},
			{
				name: 'List Links',
				value: 'listLinks',
				description: 'Get all links',
				action: 'List links',
				routing: {
					request: {
						method: 'GET',
						url: '/resources/links',
					},
					output: {
						postReceive: [
							{
								type: 'rootProperty',
								properties: {
									property: 'links',
								},
							},
						],
					},
				},
			},
			{
				name: 'Get Device Links',
				value: 'getDeviceLinks',
				description: 'Get links for a specific device',
				action: 'Get device links',
				routing: {
					request: {
						method: 'GET',
						url: '=/devices/{{$parameter.deviceId}}/links',
					},
					output: {
						postReceive: [
							{
								type: 'rootProperty',
								properties: {
									property: 'links',
								},
							},
						],
					},
				},
			},
			{
				name: 'Get Link',
				value: 'getLink',
				description: 'Get a specific link by ID',
				action: 'Get link',
				routing: {
					request: {
						method: 'GET',
						url: '=/resources/links/{{$parameter.linkId}}',
					},
					output: {
						postReceive: [
							{
								type: 'rootProperty',
								properties: {
									property: 'links',
								},
							},
						],
					},
				},
			},
			{
				name: 'List FDB',
				value: 'listFdb',
				description: 'Get FDB entries',
				action: 'List FDB entries',
				routing: {
					request: {
						method: 'GET',
						url: '=/resources/fdb{{$parameter.macAddress ? "/" + $parameter.macAddress : ""}}',
					},
					output: {
						postReceive: [
							{
								type: 'rootProperty',
								properties: {
									property: 'ports_fdb',
								},
							},
						],
					},
				},
			},
			{
				name: 'Get FDB Details',
				value: 'getFdbDetails',
				description: 'Get detailed FDB information for MAC address',
				action: 'Get FDB details',
				routing: {
					request: {
						method: 'GET',
						url: '=/resources/fdb/{{$parameter.macAddress}}/detail',
					},
				},
			},
			{
				name: 'List NAC',
				value: 'listNac',
				description: 'Get NAC entries',
				action: 'List NAC entries',
				routing: {
					request: {
						method: 'GET',
						url: '=/resources/nac{{$parameter.macAddress ? "/" + $parameter.macAddress : ""}}',
					},
					output: {
						postReceive: [
							{
								type: 'rootProperty',
								properties: {
									property: 'ports_nac',
								},
							},
						],
					},
				},
			},
		],
		default: 'listVlans',
	},
];

export const switchingFields: INodeProperties[] = [
	// Device ID for device-specific operations
	{
		displayName: 'Device',
		name: 'deviceId',
		type: 'string',
		required: true,
		displayOptions: {
			show: {
				resource: ['switching'],
				operation: ['getDeviceVlans', 'getDeviceLinks'],
			},
		},
		default: '',
		placeholder: 'hostname or device ID',
		description: 'Device hostname or ID',
	},

	// Link ID for specific link operations
	{
		displayName: 'Link ID',
		name: 'linkId',
		type: 'string',
		required: true,
		displayOptions: {
			show: {
				resource: ['switching'],
				operation: ['getLink'],
			},
		},
		default: '',
		description: 'Link ID',
	},

	// MAC address for FDB/NAC operations
	{
		displayName: 'MAC Address',
		name: 'macAddress',
		type: 'string',
		displayOptions: {
			show: {
				resource: ['switching'],
				operation: ['listFdb', 'getFdbDetails', 'listNac'],
			},
		},
		default: '',
		placeholder: '00:11:22:33:44:55',
		description: 'MAC address to filter by (optional for list operations)',
	},
];
