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

export const packageTools = [
  {
    name: 'acuity_list_packages',
    description: 'List all appointment packages',
    inputSchema: {
      type: 'object',
      properties: {},
    },
    handler: async (args: any, client: AcuityClient) => {
      const packages = await client.getPackages();
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(packages, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_get_package',
    description: 'Get a specific package by ID',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Package ID',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const pkg = await client.getPackage(args.id);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(pkg, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_create_package',
    description: 'Create a new appointment package',
    inputSchema: {
      type: 'object',
      properties: {
        name: {
          type: 'string',
          description: 'Package name',
        },
        price: {
          type: 'string',
          description: 'Package price (e.g., "200.00")',
        },
        numberOfSessions: {
          type: 'number',
          description: 'Number of sessions included',
        },
        appointmentTypeIDs: {
          type: 'array',
          items: { type: 'number' },
          description: 'Array of appointment type IDs',
        },
      },
      required: ['name', 'price', 'numberOfSessions', 'appointmentTypeIDs'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const pkg = await client.createPackage(args);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(pkg, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_update_package',
    description: 'Update an existing package',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Package ID',
        },
        name: {
          type: 'string',
          description: 'Updated name',
        },
        price: {
          type: 'string',
          description: 'Updated price',
        },
        numberOfSessions: {
          type: 'number',
          description: 'Updated number of sessions',
        },
        appointmentTypeIDs: {
          type: 'array',
          items: { type: 'number' },
          description: 'Updated appointment type IDs',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const { id, ...updateParams } = args;
      const pkg = await client.updatePackage(id, updateParams);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(pkg, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_delete_package',
    description: 'Delete a package',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Package ID to delete',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      await client.deletePackage(args.id);
      return {
        content: [
          {
            type: 'text',
            text: `Package ${args.id} deleted successfully`,
          },
        ],
      };
    },
  },
];
