import { INodeProperties } from 'n8n-workflow';

export const inventoryOperations: INodeProperties[] = [
	{
		displayName: 'Operation',
		name: 'operation',
		type: 'options',
		noDataExpression: true,
		displayOptions: {
			show: {
				resource: ['inventory'],
			},
		},
		options: [
			{
				name: 'Get Inventory',
				value: 'getInventory',
				description: 'Get device inventory (hierarchical)',
				action: 'Get device inventory',
				routing: {
					request: {
						method: 'GET',
						url: '=/inventory/{{$parameter.deviceId}}',
					},
					output: {
						postReceive: [
							{
								type: 'rootProperty',
								properties: {
									property: 'inventory',
								},
							},
						],
					},
				},
			},
			{
				name: 'Get All Inventory',
				value: 'getAllInventory',
				description: 'Get all device inventory (flattened)',
				action: 'Get all device inventory',
				routing: {
					request: {
						method: 'GET',
						url: '=/inventory/{{$parameter.deviceId}}/all',
					},
					output: {
						postReceive: [
							{
								type: 'rootProperty',
								properties: {
									property: 'inventory',
								},
							},
						],
					},
				},
			},
		],
		default: 'getInventory',
	},
];

export const inventoryFields: INodeProperties[] = [
	// Device ID for inventory operations
	{
		displayName: 'Device',
		name: 'deviceId',
		type: 'string',
		required: true,
		displayOptions: {
			show: {
				resource: ['inventory'],
				operation: ['getInventory', 'getAllInventory'],
			},
		},
		default: '',
		placeholder: 'hostname or device ID',
		description: 'Device hostname or ID',
	},

	// Filters for hierarchical inventory
	{
		displayName: 'Filters',
		name: 'filters',
		type: 'collection',
		placeholder: 'Add Filter',
		default: {},
		displayOptions: {
			show: {
				resource: ['inventory'],
				operation: ['getInventory'],
			},
		},
		options: [
			{
				displayName: 'Physical Class',
				name: 'entPhysicalClass',
				type: 'options',
				options: [
					{ name: 'Chassis', value: 'chassis' },
					{ name: 'Backplane', value: 'backplane' },
					{ name: 'Container', value: 'container' },
					{ name: 'Power Supply', value: 'powerSupply' },
					{ name: 'Fan', value: 'fan' },
					{ name: 'Sensor', value: 'sensor' },
					{ name: 'Module', value: 'module' },
					{ name: 'Port', value: 'port' },
					{ name: 'Stack', value: 'stack' },
					{ name: 'Other', value: 'other' },
					{ name: 'Unknown', value: 'unknown' },
				],
				default: '',
				description: 'Filter by physical class',
				routing: {
					send: {
						type: 'query',
						property: 'entPhysicalClass',
					},
				},
			},
			{
				displayName: 'Physical Contained In',
				name: 'entPhysicalContainedIn',
				type: 'string',
				default: '',
				description: 'Filter by parent component index',
				routing: {
					send: {
						type: 'query',
						property: 'entPhysicalContainedIn',
					},
				},
			},
		],
	},
];
