import { definePlugin, createPaginatedPluginMethod, } from "../../../utils/plugin-utils";
import { ListTriggerInputFieldsSchema } from "./schemas";
import { RootFieldItemSchema } from "../../../schemas/Field";
import { appKeyResolver, actionKeyResolver, connectionIdResolver, inputsAllOptionalResolver, } from "../../../resolvers";
import { triggersDefaults } from "../shared";
import { DEFAULT_PAGE_SIZE } from "../../../constants";
export const listTriggerInputFieldsPlugin = definePlugin((sdk) => createPaginatedPluginMethod(sdk, {
    ...triggersDefaults,
    name: "listTriggerInputFields",
    type: "list",
    itemType: "RootField",
    inputSchema: ListTriggerInputFieldsSchema,
    outputSchema: RootFieldItemSchema,
    defaultPageSize: DEFAULT_PAGE_SIZE,
    // actionKeyResolver and inputsAllOptionalResolver depend on actionType.
    // Pin it to "read" so they resolve correctly without the user setting it.
    resolvers: {
        app: appKeyResolver,
        action: actionKeyResolver,
        connection: connectionIdResolver,
        inputs: inputsAllOptionalResolver,
        actionType: { type: "constant", value: "read" },
    },
    handler: async ({ sdk, options, }) => {
        // Thin pass-through to listActionInputFields with actionType pinned.
        // Awaiting the paginated method returns the first page.
        const result = await sdk.listActionInputFields({
            ...options,
            actionType: "read",
        });
        return { data: result.data, nextCursor: result.nextCursor };
    },
}));
