import { definePlugin } from "../../utils/plugin-utils";
import { createPaginatedPluginMethod } from "../../utils/plugin-utils";
import { ListClientCredentialsQuerySchema } from "./schemas";
import { extractCursor } from "../../utils/function-utils";
import { DEFAULT_PAGE_SIZE } from "../../constants";
import { ClientCredentialsItemSchema } from "../../schemas/ClientCredentials";
export const listClientCredentialsPlugin = definePlugin((sdk) => createPaginatedPluginMethod(sdk, {
    name: "listClientCredentials",
    categories: ["client-credentials"],
    type: "list",
    itemType: "ClientCredentials",
    inputSchema: ListClientCredentialsQuerySchema,
    outputSchema: ClientCredentialsItemSchema,
    defaultPageSize: DEFAULT_PAGE_SIZE,
    handler: async ({ sdk, options, }) => {
        const searchParams = {};
        if (options.pageSize !== undefined) {
            searchParams.page_size = options.pageSize.toString();
        }
        if (options.cursor) {
            searchParams.offset = options.cursor;
        }
        return sdk.context.api.get("/api/v0/client-credentials", {
            searchParams,
            authRequired: true,
            requiredScopes: ["credentials"],
        });
    },
    extractCursor: (response) => extractCursor(response.links),
}));
