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

const inputSchema = {
  action: z.string().describe('Action to confirm'),
};

const outputSchema = z.object({
  message: z.string(),
  confirmed: z.boolean(),
});

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

@Tool({
  name: 'confirm-action',
  description: 'Demonstrates simple confirmation elicitation. Asks user to confirm an action before proceeding.',
  inputSchema,
  outputSchema,
})
export default class ConfirmActionTool extends ToolContext {
  async execute(input: Input): Promise<Output> {
    const result = await this.elicit(
      `Do you want to proceed with: ${input.action}?`,
      z.object({
        confirmed: z.boolean().describe('Confirm action'),
      }),
    );

    if (result.status === 'accept' && result.content?.confirmed) {
      return {
        message: `Action "${input.action}" confirmed and executed`,
        confirmed: true,
      };
    }

    return {
      message: `Action "${input.action}" was cancelled`,
      confirmed: false,
    };
  }
}
