<%- include('../partials/generatedHeader.ejs') -%>
import { ConfigVarExpression } from "@prismatic-io/spectral";
import {
  findUserDefinedComponentKey,
  requireIntegrationContext,
} from "@prismatic-io/spectral/dist/serverTypes";
<%- include('../partials/imports.ejs', { imports, helpers }) %>

export interface <%= trigger.typeInterface %>Values {
<%- include('../partials/performArgs.ejs', { inputs: trigger.inputs, helpers }) -%>
}

/**
 * <%= trigger.label %>
 *
 * @description <%- trigger.description %>
 * This object is used to support type hinting.
 */
export const <%= trigger.import %> = {
  key: "<%= trigger.key %>",
  perform: <TReturn>(
    _values: <%= trigger.typeInterface %>Values
  ): Promise<TReturn> => Promise.resolve<TReturn>({} as TReturn),
  inputs: {
    <%- include('../partials/inputs.ejs', { inputs: trigger.inputs, helpers }) -%>
  }
} as const;

/**
 * <%= trigger.label %> Trigger Helper
 *
 * @comments This wrapper function can be used directly in flow definitions.
 */
export const <%= helpers.camelCase(trigger.componentKey) %><%= helpers.capitalizeFirstLetter(trigger.import) %> = (values: {
  <% trigger.inputs.forEach((input) => { -%>
    <%- helpers.formatType(input.key) %><%= input.required ? "" : "?" %>: ({
      value: <%- input.valueType.type ? input.valueType.type : input.valueType %>;
    } | ConfigVarExpression);
  <% }); -%>
}) => {
  return {
    get component() {
      const context = requireIntegrationContext();
      return findUserDefinedComponentKey(
        "<%= trigger.componentKey %>",
        <%= trigger.componentIsPublic %>,
        context.componentRegistry,
      );
    },
    key: "<%= trigger.key %>",
    values,
  } as const;
};
