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

export function createProductsTools(client: AcuityClient) {
  return {
    acuity_list_products: {
      description: 'List all products (add-ons, packages, subscriptions, gift certificates)',
      inputSchema: z.object({
        type: z.enum(['addons', 'packages', 'subscriptions', 'certificates']).optional()
          .describe('Filter by product type')
      }),
      handler: async (args: any) => {
        const products = await client.listProducts(args.type);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(products, null, 2)
          }]
        };
      }
    },

    acuity_get_product: {
      description: 'Get a specific product by ID',
      inputSchema: z.object({
        id: z.number().describe('Product ID')
      }),
      handler: async (args: any) => {
        const product = await client.getProduct(args.id);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(product, null, 2)
          }]
        };
      }
    },

    acuity_list_addons: {
      description: 'List all add-on products',
      inputSchema: z.object({}),
      handler: async () => {
        const products = await client.listProducts('addons');
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(products, null, 2)
          }]
        };
      }
    },

    acuity_list_packages: {
      description: 'List all package products',
      inputSchema: z.object({}),
      handler: async () => {
        const products = await client.listProducts('packages');
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(products, null, 2)
          }]
        };
      }
    },

    acuity_list_subscriptions: {
      description: 'List all subscription products',
      inputSchema: z.object({}),
      handler: async () => {
        const products = await client.listProducts('subscriptions');
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(products, null, 2)
          }]
        };
      }
    },

    acuity_list_gift_certificates: {
      description: 'List all gift certificate products',
      inputSchema: z.object({}),
      handler: async () => {
        const products = await client.listProducts('certificates');
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(products, null, 2)
          }]
        };
      }
    }
  };
}
