import { definePlugin } from "../../../utils/plugin-utils";
import { createPluginMethod } from "../../../utils/plugin-utils";
import { DeleteTableRecordsOptionsInputSchema } from "./schemas";
import { tableIdResolver, tableRecordIdsResolver } from "../../../resolvers";
import { tablesDefaults } from "../shared";
export const deleteTableRecordsPlugin = definePlugin((sdk) => createPluginMethod(sdk, {
    ...tablesDefaults,
    name: "deleteTableRecords",
    type: "delete",
    itemType: "Record",
    inputSchema: DeleteTableRecordsOptionsInputSchema,
    resolvers: { table: tableIdResolver, records: tableRecordIdsResolver },
    confirm: "delete",
    handler: async ({ sdk, options }) => {
        const tableId = "table" in options ? options.table : options.tableId;
        const recordIds = "records" in options ? options.records : options.recordIds;
        await sdk.context.api.delete(`/tables/api/v1/tables/${tableId}/records`, { record_ids: recordIds }, {
            authRequired: true,
            resource: { type: "table", id: tableId },
        });
        return { success: true };
    },
}));
