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

import { crmStore } from '../data/crm.store';

const inputSchema = {
  id: z.string().describe('User ID'),
};

const outputSchema = z.object({
  user: z
    .object({
      id: z.string(),
      name: z.string(),
      email: z.string(),
      company: z.string(),
      role: z.string(),
      createdAt: z.string(),
    })
    .nullable(),
});

@Tool({
  name: 'users-get',
  description: 'Get a specific user by ID',
  inputSchema,
  outputSchema,
})
export default class UsersGetTool extends ToolContext {
  async execute(input: z.infer<z.ZodObject<typeof inputSchema>>): Promise<z.infer<typeof outputSchema>> {
    const user = crmStore.getUser(input.id);
    return { user: user || null };
  }
}
