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

export const taskOperations: INodeProperties[] = [
	{
		displayName: 'Operation',
		name: 'operation',
		type: 'options',
		noDataExpression: true,
		required: true,
		displayOptions: {
			show: {
				resource: [
					'task',
				],
			},
		},
		options: [
			{
				name: 'Copy',
				value: 'copy',
				description: 'Copy a task',
				action: 'Copy a task',
			},
			{
				name: 'Create',
				value: 'create',
				description: 'Create a new task',
				action: 'Create a task',
			},
			{
				name: 'Delete',
				value: 'delete',
				description: 'Delete a task',
				action: 'Delete a task',
			},
			{
				name: 'Get',
				value: 'get',
				description: 'Get tasks',
				action: 'Get a task',
			},
			{
				name: 'Move',
				value: 'move',
				description: 'Move a task',
				action: 'Move a task',
			},
			{
				name: 'Update',
				value: 'update',
				description: 'Update a task',
				action: 'Update a task',
			},
		],
		default: 'create',
	},
];

export const taskDescription: INodeProperties[] = [
	{
		displayName: 'Task ID',
		name: '_id',
		type: 'string',
		default: '',
		displayOptions: {
			show: {
				resource: [
					'task',
				],
				operation: [
					'update',
					'move',
					'copy',
					'delete',
				],
			},
		},
		description: 'ID of task',
	},
	// Options for creating and updating task.
	{
		displayName: 'Options',
		name: 'options',
		type: 'collection',
		placeholder: 'Add Option',
		default: {},
		displayOptions: {
			show: {
				resource: [
					'task',
				],
				operation: [
					'create',
					'update',
				],
			},
		},
		options: [
			{
				displayName: 'Project Name or ID',
				name: 'projectId',
				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: 'getProjectId',
				},
			},
			{
				displayName: 'Task Board Name or ID',
				name: 'taskBoardId',
				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: 'getTaskBoardId',
				},
			},
			{
				displayName: 'Task Group Name or ID',
				name: 'taskGroupId',
				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: 'getTaskGroupId',
				},
			},
			{
				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: 'getTaskTemplateId',
				},
			},
			{
				displayName: 'Creator Name or ID',
				name: 'createdBy',
				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: 'getUsers',
				},
			},
			{
				displayName: 'Title',
				name: 'title',
				type: 'string',
				default: '',
				description: 'Title of the task',
			},
			{
				displayName: 'Description',
				name: 'descriptionHTML',
				type: 'string',
				default: '',
				description: 'Request Description',
			},
			{
				displayName: 'Custom Fields',
				name: 'customFields',
				type: 'fixedCollection',
				placeholder: 'Add Custom Field',
				typeOptions: {
					multipleValues: true,
				},
				description: 'Key value pairs containing the name and value of the custom field. Only dates in the format YYYY-MM-DD are accepted as input for custom date fields.',
				default: [],
				options: [
					{
						displayName: 'Custom Field',
						name: 'customField',
						values: [
							{
								displayName: 'Custom Field Name or ID',
								name: '_id',
								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: 'getCustomFieldTitle',
								},

							},
							{
								displayName: 'Value Name or ID',
								name: 'value',
								type: 'string',
								default: '',
								description: 'Custom Field\'s values',
							},
						],
					},
				],
			},
		],
	},
	{
		displayName: 'Assigned To: Name or ID',
		name: 'assignees',
		type: 'fixedCollection',
		default: [],
		placeholder: 'Add Person',
		typeOptions: {
			multipleValues: true,
		},
		displayOptions: {
			show: {
				resource: [
					'task',
				],
				operation: [
					'update',
					'create',
				],
			},
		},
		options: [
			{
				displayName: 'Assignee',
				name: 'assignee',
				values: [
					{
						displayName: 'Assigned To: Name or ID',
						name: 'value',
						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: 'getUsers',
						},
					},
				],
			},
		],
		description: 'Name or ID of the user to whom the task has been assigned. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/nodes/expressions.html#expressions">expression</a>.',
	},
	// move & copy task operation
	{
		displayName: 'Task Group Name or ID',
		name: 'taskGroupId',
		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: 'getTaskGroupId',
		},
		displayOptions: {
			show: {
				resource: [
					'task',
				],
				operation: [
					'move',
					'copy',
				],
			},
		},
	},
	{
		displayName: 'Position',
		name: 'position',
		type: 'number',
		default: '',
		displayOptions: {
			show: {
				resource: [
					'task',
				],
				operation: [
					'move',
					'copy',
				],
			},
		},
		description: 'Should be a number representing task ID after which task should be moved',
	},
	// Options for GET request
	{
		displayName: 'Options',
		name: 'options',
		type: 'collection',
		placeholder: 'Add Option',
		default: {},
		displayOptions: {
			show: {
				resource: [
					'task',
				],
				operation: [
					'get',
				],
			},
		},
		options: [
			{
				displayName: 'Task ID',
				name: '_id',
				type: 'string',
				default: '',
				description: 'ID of task',
			},
			{
				displayName: 'Project Name or ID',
				name: 'projectId',
				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: 'getProjectId',
				},
			},
			{
				displayName: 'Task Board Name or ID',
				name: 'taskBoardId',
				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: 'getTaskBoardId',
				},
			},
			{
				displayName: 'Task Group Name or ID',
				name: 'taskGroupId',
				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: 'getTaskGroupId',
				},
			},
			{
				displayName: 'Creator Name or ID',
				name: 'createdBy',
				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: 'getUsers',
				},
			},
			{
				displayName: 'Title',
				name: 'title',
				type: 'string',
				default: '',
			},
		],
	},
];