import { definePlugin, createPluginMethod } from "../../../utils/plugin-utils";
import { PauseTriggerInboxSchema, TriggerInboxItemSchema } from "./schemas";
import { triggerInboxResolver } from "../../../resolvers";
import { resolveTriggerInboxId } from "../utils";
import { triggersDefaults } from "../shared";
export const pauseTriggerInboxPlugin = definePlugin((sdk) => createPluginMethod(sdk, {
    ...triggersDefaults,
    name: "pauseTriggerInbox",
    type: "update",
    itemType: "TriggerInbox",
    inputSchema: PauseTriggerInboxSchema,
    outputSchema: TriggerInboxItemSchema,
    resolvers: { inbox: triggerInboxResolver },
    handler: async ({ sdk, options }) => {
        const { inbox } = options;
        const inboxId = await resolveTriggerInboxId({
            api: sdk.context.api,
            inbox,
        });
        const rawResponse = await sdk.context.api.post(`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}/pause`, undefined, {
            authRequired: true,
            resource: { type: "trigger_inbox", id: inboxId },
        });
        return { data: TriggerInboxItemSchema.parse(rawResponse) };
    },
}));
