import { definePlugin } from "../../utils/plugin-utils";
import { createPluginMethod } from "../../utils/plugin-utils";
import { CreateClientCredentialsSchema } from "./schemas";
import { ClientCredentialsCreatedItemSchema } from "../../schemas/ClientCredentials";
import { clientCredentialsNameResolver } from "../../resolvers";
export const createClientCredentialsPlugin = definePlugin((sdk) => createPluginMethod(sdk, {
    name: "createClientCredentials",
    categories: ["client-credentials"],
    type: "create",
    itemType: "ClientCredentials",
    inputSchema: CreateClientCredentialsSchema,
    outputSchema: ClientCredentialsCreatedItemSchema,
    confirm: "create-secret",
    resolvers: { name: clientCredentialsNameResolver },
    handler: async ({ sdk, options }) => {
        const { api } = sdk.context;
        const response = await api.post("/api/v0/client-credentials", {
            name: options.name,
            allowed_scopes: options.allowedScopes,
            ...(options.policy && { policy: options.policy }),
        }, {
            authRequired: true,
            requiredScopes: ["credentials"],
        });
        return { data: response.data };
    },
}));
