import { definePlugin, createPluginMethod } from "../../../utils/plugin-utils";
import { ResumeTriggerInboxSchema, TriggerInboxItemSchema } from "./schemas";
import { triggerInboxResolver } from "../../../resolvers";
import { resolveTriggerInboxId } from "../utils";
import { triggersDefaults } from "../shared";
export const resumeTriggerInboxPlugin = definePlugin((sdk) => createPluginMethod(sdk, {
    ...triggersDefaults,
    name: "resumeTriggerInbox",
    type: "update",
    itemType: "TriggerInbox",
    inputSchema: ResumeTriggerInboxSchema,
    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)}/resume`, undefined, {
            authRequired: true,
            resource: { type: "trigger_inbox", id: inboxId },
        });
        return { data: TriggerInboxItemSchema.parse(rawResponse) };
    },
}));
