import { EditorLanguage, ExtendedIntegrationPluginId, FormComponentType, FormSectionLayout, PluginResponseType, PluginType } from '../../types/index.js';
import { PUBLIC_INTEGRATIONS_LOGO_URL } from './constants.js';
import { GraphQLPluginVersions } from './graphql.js';
import { authSections } from './shared/index.js';
const GraphQLIntegrationPluginVersions = GraphQLPluginVersions;
export var GraphQLIntegrationPluginMergedFieldNames;
(function (GraphQLIntegrationPluginMergedFieldNames) {
    GraphQLIntegrationPluginMergedFieldNames["HEADERS"] = "headers";
    // potentially variables too if converted to FieldList component
    // VARIABLES = 'custom.variables.value'
})(GraphQLIntegrationPluginMergedFieldNames || (GraphQLIntegrationPluginMergedFieldNames = {}));
export const GraphQLIntegrationPlugin = {
    id: ExtendedIntegrationPluginId.GRAPHQL,
    name: 'GraphQL',
    moduleName: 'GraphQLPlugin',
    modulePath: 'plugins/graphql/GraphQLPlugin',
    iconLocation: `${PUBLIC_INTEGRATIONS_LOGO_URL}/graphql.png`,
    type: PluginType.API,
    responseType: PluginResponseType.JSON,
    hasRawRequest: true,
    rawRequestName: 'Executed request',
    hasTest: false,
    datasourceTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        label: 'Display name',
                        name: 'name',
                        startVersion: GraphQLIntegrationPluginVersions.V1,
                        componentType: FormComponentType.INPUT_TEXT,
                        placeholder: 'Example API',
                        rules: [{ required: true, message: 'Display name is required' }]
                    },
                    {
                        label: 'URL',
                        name: 'path',
                        startVersion: GraphQLIntegrationPluginVersions.V1,
                        componentType: FormComponentType.DYNAMIC_INPUT_TEXT,
                        placeholder: 'https://swapi-graphql.netlify.app/.netlify/functions/index',
                        rules: [{ required: true, message: 'URL is required' }]
                    }
                ]
            },
            ...authSections({
                startVersion: GraphQLIntegrationPluginVersions.V8,
                pluginId: ExtendedIntegrationPluginId.GRAPHQL,
                pluginName: 'GraphQL',
                enabledMethods: {
                    basic: true,
                    oauth: true,
                    bearer: true,
                    apiKey: true
                }
            }),
            {
                name: 'tabs',
                layout: FormSectionLayout.TABS,
                items: [
                    {
                        label: 'Headers',
                        name: GraphQLIntegrationPluginMergedFieldNames.HEADERS,
                        startVersion: GraphQLIntegrationPluginVersions.V1,
                        componentType: FormComponentType.FIELD_LIST,
                        secretsNames: ['Authorization']
                    }
                ]
            }
        ]
    },
    actionTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        label: 'URL',
                        name: 'path',
                        startVersion: GraphQLIntegrationPluginVersions.V1,
                        componentType: FormComponentType.INPUT_TEXT,
                        disabled: true
                    }
                ]
            },
            {
                name: 'tabs',
                layout: FormSectionLayout.TABS,
                items: [
                    {
                        label: 'Query',
                        name: 'body',
                        startVersion: GraphQLIntegrationPluginVersions.V1,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.JSON
                    },
                    {
                        label: 'Variables',
                        name: 'custom.variables.value',
                        startVersion: GraphQLIntegrationPluginVersions.V1,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.JSON
                    },
                    {
                        label: 'Headers',
                        name: GraphQLIntegrationPluginMergedFieldNames.HEADERS,
                        startVersion: GraphQLIntegrationPluginVersions.V1,
                        componentType: FormComponentType.FIELD_LIST
                    }
                ]
            },
            {
                name: 'additionalSettings',
                sectionHeader: 'Additional Settings',
                isCollapsible: true,
                defaultCollapsed: true,
                asTitle: false,
                items: [
                    {
                        name: 'verboseHttpOutput',
                        label: 'Include full request response in step output',
                        lightLabelText: true,
                        startVersion: GraphQLIntegrationPluginVersions.V9,
                        componentType: FormComponentType.SWITCH,
                        initialValue: false,
                        showConfirm: false,
                        renderIconFirst: true
                    },
                    {
                        name: 'failOnGraphqlErrors',
                        label: 'Fail when request includes errors',
                        lightLabelText: true,
                        startVersion: GraphQLIntegrationPluginVersions.V10,
                        componentType: FormComponentType.SWITCH,
                        initialValue: false,
                        showConfirm: false,
                        renderIconFirst: true
                    }
                ]
            }
        ]
    }
};
//# sourceMappingURL=graphqlintegration.js.map