import {
	INodeProperties,
} from 'n8n-workflow';

export const invoiceOperations: INodeProperties[] = [
	{
		displayName: 'Operation',
		name: 'operation',
		type: 'options',
		noDataExpression: true,
		required: true,
		displayOptions: {
			show: {
				resource: [
					'invoice',
				],
			},
		},
		options: [
			{
				name: 'Create',
				value: 'create',
				description: 'Create a new invoice',
				action: 'Create an invoice',
			},
			{
				name: 'Get',
				value: 'get',
				description: 'Get invoices',
				action: 'Get an invoice',
			},
			{
				name: 'Update',
				value: 'update',
				description: 'Update an invoice',
				action: 'Update an invoice',
			},
			{
				name: 'Delete',
				value: 'delete',
				description: 'Delete an invoice',
				action: 'Delete an invoice',
			},
		],
		default: 'create',
	},
];

export const invoiceDescription: INodeProperties[] = [
	{
		displayName: 'Invoice ID',
		name: '_id',
		type: 'string',
		default: '',
		displayOptions: {
			show: {
				resource: [
					'invoice',
				],
				operation: [
					'update',
					'delete',
				],
			},
		},
		description: 'Should be a number or string for discount percentage',
	},
	{
		displayName: 'Tax',
		name: 'taxUi',
		type: 'fixedCollection',
		placeholder: 'Add Tax',
		description: 'Key value pairs containing the title and value of the tax',
		displayOptions: {
			show: {
				resource: [
					'invoice',
				],
				operation: [
					'create',
					'update',
				],
			},
		},
		typeOptions: {
			multipleValues: true,
		},
		default: [],
		options: [
			{
				displayName: 'Tax',
				name: 'tax',
				values: [
					{
						displayName: 'Title',
						name: 'title',
						type: 'string',
						default: '',
						description: 'Tax title',
					},
					{
						displayName: 'Value',
						name: 'value',
						type: 'number',
						default: '',
						description: 'Tax value',
					},
				],
			},
		],
	},
	{
		displayName: 'Client',
		name: 'clientUi',
		type: 'fixedCollection',
		placeholder: 'Add Client',
		description: 'Key value pairs containing the title and value of the tax',
		default: [],
		displayOptions: {
			show: {
				resource: [
					'invoice',
				],
				operation: [
					'create',
					'update',
				],
			},
		},
		options: [
			{
				displayName: 'Client',
				name: 'client',
				values: [
					{
						displayName: 'Entity Type',
						name: 'entityType',
						type: 'options',
						default: 'person',
						options: [
							{
								name: 'Person',
								value: 'person',
							},
							{
								name: 'Company',
								value: 'company',
							},
						],
						description: 'Entity Type could be a person or company',
					},
					{
						displayName: 'Entity Name or ID',
						name: '_id',
						type: 'string',
						default: '',
						description: 'Could be a person or company\'s name or ID',
					},
				],
			},
		],
	},
	{
		displayName: 'Options',
		name: 'options',
		type: 'collection',
		placeholder: 'Add Option',
		default: {},
		displayOptions: {
			show: {
				resource: [
					'invoice',
				],
				operation: [
					'create',
				],
			},
		},
		options: [
			{
				displayName: 'Invoice Name',
				name: 'name',
				type: 'string',
				default: '',
				description: 'Min-Max Character: 1-500',
			},
			{
				displayName: 'Currency',
				name: 'currency',
				type: 'options',
				default: 'USD',
				options: [
					{
						name: 'USD',
						value: 'USD',
					},
					{
						name: 'EUR',
						value: 'EUR',
					},
				],
			},
			{
				displayName: 'Discount',
				name: 'discount',
				type: 'number',
				default: '',
				description: 'Should be a number for discount percentage',
			},
			{
				displayName: 'Template Name or ID',
				name: 'templateId',
				type: 'options',
				description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
				default: '',
				typeOptions: {
					loadOptionsMethod: 'getInvoiceTemplateId',
				},
			},
		],
	},
	// Options for GET Request
	{
		displayName: 'Options',
		name: 'options',
		type: 'collection',
		placeholder: 'Add Option',
		default: {},
		displayOptions: {
			show: {
				resource: [
					'invoice',
				],
				operation: [
					'get',
				],
			},
		},
		options: [
			{
				displayName: 'Invoice ID',
				name: '_id',
				type: 'string',
				default: '',
				description: 'Should be a number for discount percentage',
			},
			{
				displayName: 'Invoice Name',
				name: 'name',
				type: 'string',
				default: '',
				description: 'Min-Max Character: 1-500',
			},
			{
				displayName: 'Currency',
				name: 'currency',
				type: 'options',
				default: 'USD',
				options: [
					{
						name: 'USD',
						value: 'USD',
					},
					{
						name: 'EUR',
						value: 'EUR',
					},
				],
			},
			{
				displayName: 'Status',
				name: 'status',
				type: 'options',
				default: 'draft',
				options: [
					{
						name: 'Draft',
						value: 'draft',
					},
					{
						name: 'Pending',
						value: 'pending',
					},
					{
						name: 'Paid',
						value: 'paid',
					},
					{
						name: 'Cancelled',
						value: 'cancelled',
					},
				],
			},
			{
				displayName: 'Discount',
				name: 'discount',
				type: 'number',
				default: '',
				description: 'Should be a number for discount percentage',
			},
		],
	},
	// Options for Update Operation
	{
		displayName: 'Options',
		name: 'options',
		type: 'collection',
		placeholder: 'Add Option',
		default: {},
		displayOptions: {
			show: {
				resource: [
					'invoice',
				],
				operation: [
					'update',
				],
			},
		},
		options: [
			{
				displayName: 'Invoice Name',
				name: 'name',
				type: 'string',
				default: '',
				description: 'Min-Max Character: 1-500',
			},
			{
				displayName: 'Currency',
				name: 'currency',
				type: 'options',
				default: 'USD',
				options: [
					{
						name: 'USD',
						value: 'USD',
					},
					{
						name: 'EUR',
						value: 'EUR',
					},
				],
			},
			{
				displayName: 'Status',
				name: 'status',
				type: 'options',
				default: 'draft',
				options: [
					{
						name: 'Draft',
						value: 'draft',
					},
					{
						name: 'Pending',
						value: 'pending',
					},
					{
						name: 'Paid',
						value: 'paid',
					},
					{
						name: 'Cancelled',
						value: 'cancelled',
					},
				],
			},
			{
				displayName: 'Discount',
				name: 'discount',
				type: 'number',
				default: '',
				description: 'Should be a number for discount percentage',
			},
		],
	},
];