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