import { definePlugin, createPluginMethod } from "../../../utils/plugin-utils";
import { GetTriggerInboxSchema, TriggerInboxItemSchema } from "./schemas";
import { triggerInboxResolver } from "../../../resolvers";
import { resolveTriggerInboxId } from "../utils";
import { triggersDefaults } from "../shared";
export const getTriggerInboxPlugin = definePlugin((sdk) => createPluginMethod(sdk, {
    ...triggersDefaults,
    name: "getTriggerInbox",
    type: "item",
    itemType: "TriggerInbox",
    inputSchema: GetTriggerInboxSchema,
    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.get(`/trigger-inbox/api/v1/inboxes/${encodeURIComponent(inboxId)}`, {
            authRequired: true,
            resource: { type: "trigger_inbox", id: inboxId },
        });
        return { data: TriggerInboxItemSchema.parse(rawResponse) };
    },
}));
