import { z } from '@frontmcp/lazy-zod';
import { Tool, ToolContext } from '@frontmcp/sdk';

import '@frontmcp/plugin-remember'; // Import for this.remember types

const inputSchema = {
  scope: z
    .enum(['session', 'user', 'tool', 'global'])
    .optional()
    .default('session')
    .describe('Scope to list memories from'),
  pattern: z.string().optional().describe('Optional pattern to filter keys'),
};

const outputSchema = z.object({
  scope: z.string(),
  keys: z.array(z.string()),
  count: z.number(),
});

type Input = z.infer<z.ZodObject<typeof inputSchema>>;
type Output = z.infer<typeof outputSchema>;

@Tool({
  name: 'list-memories',
  description: 'List all stored memories in a scope',
  inputSchema,
  outputSchema,
})
export default class ListMemoriesTool extends ToolContext {
  async execute(input: Input): Promise<Output> {
    const keys = await this.remember.list({
      scope: input.scope,
      pattern: input.pattern,
    });

    return {
      scope: input.scope,
      keys,
      count: keys.length,
    };
  }
}
