/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import { featureFlagsList } from "../../funcs/featureFlagsList.js";
import * as operations from "../../models/operations/index.js";
import { formatResult, ToolDefinition } from "../tools.js";

const args = {
  request: operations.GetFeatureFlagsRequest$inboundSchema,
};

export const tool$featureFlagsList: ToolDefinition<typeof args> = {
  name: "list-feature-flags",
  description:
    `Retrieves all feature flags within a project, including metadata and targeting rules. Enables AI agents to enumerate existing flags for inspection, configuration analysis, or generating flag usage reports across environments.
`,
  scopes: ["read"],
  args,
  tool: async (client, args, ctx) => {
    const [result, apiCall] = await featureFlagsList(
      client,
      args.request,
      { fetchOptions: { signal: ctx.signal } },
    ).$inspect();

    if (!result.ok) {
      return {
        content: [{ type: "text", text: result.error.message }],
        isError: true,
      };
    }

    const value = result.value;

    return formatResult(value, apiCall);
  },
};
