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

export const subscriptionTools = [
  {
    name: 'acuity_list_subscriptions',
    description: 'List all subscription plans',
    inputSchema: {
      type: 'object',
      properties: {},
    },
    handler: async (args: any, client: AcuityClient) => {
      const subscriptions = await client.getSubscriptions();
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(subscriptions, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_get_subscription',
    description: 'Get a specific subscription by ID',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Subscription ID',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const subscription = await client.getSubscription(args.id);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(subscription, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_create_subscription',
    description: 'Create a new subscription plan',
    inputSchema: {
      type: 'object',
      properties: {
        name: {
          type: 'string',
          description: 'Subscription name',
        },
        price: {
          type: 'string',
          description: 'Subscription price (e.g., "99.00")',
        },
        frequency: {
          type: 'string',
          description: 'Billing frequency (e.g., "monthly", "weekly")',
        },
        appointmentTypeIDs: {
          type: 'array',
          items: { type: 'number' },
          description: 'Array of appointment type IDs included',
        },
      },
      required: ['name', 'price', 'frequency', 'appointmentTypeIDs'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const subscription = await client.createSubscription(args);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(subscription, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_update_subscription',
    description: 'Update an existing subscription',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Subscription ID',
        },
        name: {
          type: 'string',
          description: 'Updated name',
        },
        price: {
          type: 'string',
          description: 'Updated price',
        },
        frequency: {
          type: 'string',
          description: 'Updated frequency',
        },
        appointmentTypeIDs: {
          type: 'array',
          items: { type: 'number' },
          description: 'Updated appointment type IDs',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const { id, ...updateParams } = args;
      const subscription = await client.updateSubscription(id, updateParams);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(subscription, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_delete_subscription',
    description: 'Delete a subscription',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Subscription ID to delete',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      await client.deleteSubscription(args.id);
      return {
        content: [
          {
            type: 'text',
            text: `Subscription ${args.id} deleted successfully`,
          },
        ],
      };
    },
  },
];
