import { definePlugin } from "../../../utils/plugin-utils";
import { createPluginMethod } from "../../../utils/plugin-utils";
import { CreateTableOptionsSchema, CreateTableApiResponseSchema, TableItemSchema, } from "./schemas";
import { tableNameResolver } from "../../../resolvers";
import { transformTableItem } from "../utils";
import { tablesDefaults } from "../shared";
export const createTablePlugin = definePlugin((sdk) => createPluginMethod(sdk, {
    ...tablesDefaults,
    name: "createTable",
    type: "create",
    itemType: "Table",
    inputSchema: CreateTableOptionsSchema,
    outputSchema: TableItemSchema,
    resolvers: { name: tableNameResolver },
    handler: async ({ sdk, options }) => {
        const rawResponse = await sdk.context.api.post("/tables/api/v1/tables", { name: options.name, description: options.description }, { authRequired: true });
        const response = CreateTableApiResponseSchema.parse(rawResponse);
        return { data: transformTableItem(response.data) };
    },
}));
