import { definePlugin } from "../../../utils/plugin-utils";
import { createPluginMethod } from "../../../utils/plugin-utils";
import { DeleteTableOptionsInputSchema } from "./schemas";
import { tableIdResolver } from "../../../resolvers";
import { tablesDefaults } from "../shared";
export const deleteTablePlugin = definePlugin((sdk) => createPluginMethod(sdk, {
    ...tablesDefaults,
    name: "deleteTable",
    type: "delete",
    itemType: "Table",
    inputSchema: DeleteTableOptionsInputSchema,
    resolvers: { table: tableIdResolver },
    confirm: "delete",
    handler: async ({ sdk, options }) => {
        await sdk.context.checkCapability("canDeleteTables");
        const tableId = "table" in options ? options.table : options.tableId;
        await sdk.context.api.delete(`/tables/api/v1/tables/${tableId}`, undefined, {
            authRequired: true,
            resource: { type: "table", id: tableId },
        });
        return { success: true };
    },
}));
