import { AcuityClient } from '../clients/acuity.js';

export const productTools = [
  {
    name: 'acuity_list_products',
    description: 'List all products',
    inputSchema: {
      type: 'object',
      properties: {},
    },
    handler: async (args: any, client: AcuityClient) => {
      const products = await client.getProducts();
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(products, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_get_product',
    description: 'Get a specific product by ID',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Product ID',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const product = await client.getProduct(args.id);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(product, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_create_product',
    description: 'Create a new product',
    inputSchema: {
      type: 'object',
      properties: {
        name: {
          type: 'string',
          description: 'Product name',
        },
        price: {
          type: 'string',
          description: 'Product price (e.g., "25.00")',
        },
        description: {
          type: 'string',
          description: 'Product description',
        },
        active: {
          type: 'boolean',
          description: 'Whether product is active',
        },
      },
      required: ['name', 'price'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const product = await client.createProduct(args);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(product, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_update_product',
    description: 'Update an existing product',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Product ID',
        },
        name: {
          type: 'string',
          description: 'Updated name',
        },
        price: {
          type: 'string',
          description: 'Updated price',
        },
        description: {
          type: 'string',
          description: 'Updated description',
        },
        active: {
          type: 'boolean',
          description: 'Updated active status',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const { id, ...updateParams } = args;
      const product = await client.updateProduct(id, updateParams);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(product, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_delete_product',
    description: 'Delete a product',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Product ID to delete',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      await client.deleteProduct(args.id);
      return {
        content: [
          {
            type: 'text',
            text: `Product ${args.id} deleted successfully`,
          },
        ],
      };
    },
  },
];
