import { faker } from '@faker-js/faker/locale/en';
import type {
	ICredentialsResponse,
	ITemplatesWorkflowFull,
	IWorkflowTemplateNode,
} from '@/Interface';
import type { ICredentialType } from 'n8n-workflow';

export const newFullOneNodeTemplate = (node: IWorkflowTemplateNode): ITemplatesWorkflowFull => ({
	full: true,
	id: faker.number.int(),
	name: faker.commerce.productName(),
	totalViews: 1,
	createdAt: '2021-08-24T10:40:50.007Z',
	description: faker.lorem.paragraph(),
	workflow: {
		nodes: [node],
		connections: {},
	},
	nodes: [
		{
			defaults: {},
			displayName: faker.commerce.productName(),
			icon: 'file:telegram.svg',
			iconData: {
				fileBuffer: '',
				type: 'file',
			},
			id: faker.number.int(),
			name: node.type,
		},
	],
	image: [],
	categories: [],
	user: {
		username: faker.internet.userName(),
	},
	workflowInfo: {
		nodeCount: 1,
		nodeTypes: {
			[node.type]: {
				count: 1,
			},
		},
	},
});

export const fullShopifyTelegramTwitterTemplate: ITemplatesWorkflowFull = {
	full: true,
	id: 1205,
	name: 'Promote new Shopify products on Twitter and Telegram',
	totalViews: 485,
	createdAt: '2021-08-24T10:40:50.007Z',
	description:
		'This workflow automatically promotes your new Shopify products on Twitter and Telegram. This workflow is also featured in the blog post [*6 e-commerce workflows to power up your Shopify store*](https://n8n.io/blog/no-code-ecommerce-workflow-automations/#promote-your-new-products-on-social-media).\n\n## Prerequisites\n\n- A Shopify account and [credentials](https://docs.n8n.io/integrations/credentials/shopify/)\n- A Twitter account and [credentials](https://docs.n8n.io/integrations/credentials/twitter/)\n- A Telegram account and [credentials](https://docs.n8n.io/integrations/credentials/telegram/) for the channel you want to send messages to.\n\n## Nodes\n\n- [Shopify Trigger node](https://docs.n8n.io/integrations/trigger-nodes/n8n-nodes-base.shopifytrigger/) triggers the workflow when you create a new product in Shopify.\n- [Twitter node](https://docs.n8n.io/integrations/nodes/n8n-nodes-base.twitter/) posts a tweet with the text "Hey there, my design is now on a new product! Visit my {shop name} to get this cool {product title} (and check out more {product type})".\n- [Telegram node](https://docs.n8n.io/integrations/nodes/n8n-nodes-base.telegram/) posts a message with the same text as above in a Telegram channel.',
	workflow: {
		nodes: [
			{
				name: 'Twitter',
				type: 'n8n-nodes-base.twitter',
				position: [720, -220],
				parameters: {
					text: '=Hey there, my design is now on a new product ✨\nVisit my {{$json["vendor"]}} shop to get this cool{{$json["title"]}} (and check out more {{$json["product_type"]}}) 🛍️',
					additionalFields: {},
				},
				credentials: {
					twitterOAuth1Api: 'twitter',
				},
				typeVersion: 1,
			},
			{
				name: 'Telegram',
				type: 'n8n-nodes-base.telegram',
				position: [720, -20],
				parameters: {
					text: '=Hey there, my design is now on a new product!\nVisit my {{$json["vendor"]}} shop to get this cool{{$json["title"]}} (and check out more {{$json["product_type"]}})',
					chatId: '123456',
					additionalFields: {},
				},
				credentials: {
					telegramApi: 'telegram_habot',
				},
				typeVersion: 1,
			},
			{
				name: 'product created',
				type: 'n8n-nodes-base.shopifyTrigger',
				position: [540, -110],
				webhookId: '2a7e0e50-8f09-4a2b-bf54-a849a6ac4fe0',
				parameters: {
					topic: 'products/create',
				},
				credentials: {
					shopifyApi: 'shopify_nodeqa',
				},
				typeVersion: 1,
			},
		],
		connections: {
			'product created': {
				main: [
					[
						{
							node: 'Twitter',
							type: 'main',
							index: 0,
						},
						{
							node: 'Telegram',
							type: 'main',
							index: 0,
						},
					],
				],
			},
		},
	},
	workflowInfo: {
		nodeCount: 3,
		nodeTypes: {
			'n8n-nodes-base.twitter': {
				count: 1,
			},
			'n8n-nodes-base.telegram': {
				count: 1,
			},
			'n8n-nodes-base.shopifyTrigger': {
				count: 1,
			},
		},
	},
	user: {
		username: 'lorenanda',
	},
	nodes: [
		{
			id: 49,
			icon: 'file:telegram.svg',
			name: 'n8n-nodes-base.telegram',
			defaults: {
				name: 'Telegram',
			},
			iconData: {
				type: 'file',
				fileBuffer:
					'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodH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LjcwNiAyNS4xOTgtNS43MDYgMjUuMTk4cy0uMzMgMS4zLTEuNTE0IDEuMzQ1Yy0uNDMyLjAxNi0uOTU2LS4wNzEtMS41ODItLjYxLTIuMzIzLTEuOTk4LTEwLjM1Mi03LjM5NC0xMi4xMjYtOC41OGEuMzQuMzQgMCAwMS0uMTQ2LS4yMzljLS4wMjUtLjEyNS4xMDgtLjI4LjEwOC0uMjhzMTMuOTgtMTIuNDI3IDE0LjM1Mi0xMy43MzFjLjAyOS0uMTAxLS4wNzktLjE1MS0uMjI2LS4xMDctLjkyOS4zNDItMTcuMDI1IDEwLjUwNi0xOC44MDEgMTEuNjI5LS4xMDQuMDY2LS4zOTUuMDIzLS4zOTUuMDIzIi8+PC9nPjwvc3ltYm9sPjwvc3ZnPg==',
			},
			categories: [
				{
					id: 6,
					name: 'Communication',
				},
			],
			displayName: 'Telegram',
			typeVersion: 1,
		},
		{
			id: 107,
			icon: 'file:shopify.svg',
			name: 'n8n-nodes-base.shopifyTrigger',
			defaults: {
				name: 'Shopify Trigger',
			},
			iconData: {
				type: 'file',
				fileBuffer:
					'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgNTggNjYiIGZpbGw9IiNmZmYiIGZpbGwtcnVsZT0iZXZlbm9kZCIgc3Ryb2tlPSIjMDAwIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjx1c2UgeGxpbms6aHJlZj0iI2EiIHg9Ii41IiB5PSIuNSIvPjxzeW1ib2wgaWQ9ImEiIG92ZXJmbG93PSJ2aXNpYmxlIj48ZyBzdHJva2U9Im5vbmUiIGZpbGwtcnVsZT0ibm9uemVybyI+PHBhdGggZD0iTTQ5LjI1NSAxMi40ODRhLjYzMy42MzMgMCAwMC0uNTY0LS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42OC42OCAwIDAwLS41NjQtLjU2NHoiIGZpbGw9IiM1ZThlM2UiLz48cGF0aCBkPSJNMjkuNzU4IDIyLjlsLTIuNDU0IDcuMjQyYTExLjM2IDExLjM2IDAgMDAtNC43NTItMS4xMzNjLTMuODQ4IDAtNC4wMzYgMi40MTItNC4wMzYgMy4wMTggMCAzLjI5OCA4LjYzNiA0LjU2NCA4LjYzNiAxMi4zMzMgMCA2LjEtMy44ODUgMTAuMDMtOS4xIDEwLjAzLTYuMjYgMC05LjQ2Ny0zLjg4NS05LjQ2Ny0zLjg4NWwxLjY2NS01LjU1czMuMjggMi44MyA2LjA3MyAyLjgzYTIuNDcgMi40NyAwIDAwMi41NjQtMi40OWMwLTQuMzQtNy4xLTQuNTI3LTcuMS0xMS42MTggMC01Ljk2MiA0LjI5OC0xMS43NyAxMi45MzQtMTEuNzcgMy4zOTQuMDUgNS4wMTggMSA1LjAxOCAxeiIvPjwvZz48L3N5bWJvbD48L3N2Zz4=',
			},
			categories: [
				{
					id: 2,
					name: 'Sales',
				},
			],
			displayName: 'Shopify Trigger',
			typeVersion: 1,
		},
		{
			id: 325,
			icon: 'file:x.svg',
			name: 'n8n-nodes-base.twitter',
			defaults: {
				name: 'X',
			},
			iconData: {
				type: 'file',
				fileBuffer:
					'data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjQgMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTE4LjI0NCAyLjI1aDMuMzA4bC03LjIyNyA4LjI2IDguNTAyIDExLjI0SDE2LjE3bC01LjIxNC02LjgxN0w0Ljk5IDIxLjc1SDEuNjhsNy43My04LjgzNUwxLjI1NCAyLjI1SDguMDhsNC43MTMgNi4yMzF6bS0xLjE2MSAxNy41MmgxLjgzM0w3LjA4NCA0LjEyNkg1LjExN3oiPjwvcGF0aD48L3N2Zz4K',
			},
			categories: [
				{
					id: 1,
					name: 'Marketing & Content',
				},
			],
			displayName: 'X (Formerly Twitter)',
			typeVersion: 2,
		},
	],
	categories: [
		{
			id: 2,
			name: 'Sales',
		},
		{
			id: 19,
			name: 'Marketing & Growth',
		},
	],
	image: [
		{
			id: 527,
			url: 'https://n8niostorageaccount.blob.core.windows.net/n8nio-strapi-blobs-prod/assets/89a078b208fe4c6181902608b1cd1332.png',
		},
	],
};

export const newCredentialType = (name: string): ICredentialType => ({
	name,
	displayName: name,
	documentationUrl: name,
	properties: [],
});

export const newCredential = (
	opts: Pick<ICredentialsResponse, 'type'> & Partial<ICredentialsResponse>,
): ICredentialsResponse => ({
	createdAt: faker.date.past().toISOString(),
	updatedAt: faker.date.past().toISOString(),
	id: faker.string.alphanumeric({ length: 16 }),
	name: faker.commerce.productName(),
	nodesAccess: [],
	...opts,
});

export const credentialTypeTelegram: ICredentialType = {
	name: 'telegramApi',
	displayName: 'Telegram API',
	documentationUrl: 'telegram',
	properties: [
		{
			displayName: 'Access Token',
			name: 'accessToken',
			type: 'string',
			typeOptions: {
				password: true,
			},
			default: '',
			description:
				'Chat with the <a href="https://telegram.me/botfather">bot father</a> to obtain the access token',
		},
	],
	test: {
		request: {
			baseURL: '=https://api.telegram.org/bot{{$credentials.accessToken}}',
			url: '/getMe',
		},
	},
};

export const credentialsTelegram1: ICredentialsResponse = {
	createdAt: '2023-11-23T14:26:07.969Z',
	updatedAt: '2023-11-23T14:26:07.964Z',
	id: 'YaSKdvEcT1TSFrrr1',
	name: 'Telegram account',
	type: 'telegramApi',
	nodesAccess: [
		{
			nodeType: 'n8n-nodes-base.telegram',
			date: new Date('2023-11-23T14:26:07.962Z'),
		},
		{
			nodeType: 'n8n-nodes-base.telegramTrigger',
			date: new Date('2023-11-23T14:26:07.962Z'),
		},
	],
	ownedBy: {
		id: '713ef3e7-9e65-4b0a-893c-8a653cbb2c4f',
		email: 'user@n8n.io',
		firstName: 'Player',
		lastName: 'One',
	},
	sharedWith: [],
};

export const credentialsTelegram2: ICredentialsResponse = {
	createdAt: '2023-11-23T14:26:07.969Z',
	updatedAt: '2023-11-23T14:26:07.964Z',
	id: 'YaSKdvEcT1TSFrrr2',
	name: 'Telegram account',
	type: 'telegramApi',
	nodesAccess: [
		{
			nodeType: 'n8n-nodes-base.telegram',
			date: new Date('2023-11-23T14:26:07.962Z'),
		},
		{
			nodeType: 'n8n-nodes-base.telegramTrigger',
			date: new Date('2023-11-23T14:26:07.962Z'),
		},
	],
	ownedBy: {
		id: '713ef3e7-9e65-4b0a-893c-8a653cbb2c4f',
		email: 'user@n8n.io',
		firstName: 'Player',
		lastName: 'One',
	},
	sharedWith: [],
};
