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

export const couponTools = [
  {
    name: 'acuity_list_coupons',
    description: 'List all coupons',
    inputSchema: {
      type: 'object',
      properties: {},
    },
    handler: async (args: any, client: AcuityClient) => {
      const coupons = await client.getCoupons();
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(coupons, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_get_coupon',
    description: 'Get a specific coupon by ID',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Coupon ID',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const coupon = await client.getCoupon(args.id);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(coupon, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_create_coupon',
    description: 'Create a new coupon',
    inputSchema: {
      type: 'object',
      properties: {
        code: {
          type: 'string',
          description: 'Coupon code',
        },
        discount: {
          type: 'string',
          description: 'Discount amount or percentage (e.g., "10%" or "5.00")',
        },
        appointmentTypeIDs: {
          type: 'array',
          items: { type: 'number' },
          description: 'Array of appointment type IDs this coupon applies to',
        },
        expirationDate: {
          type: 'string',
          description: 'Expiration date (YYYY-MM-DD)',
        },
      },
      required: ['code', 'discount'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const coupon = await client.createCoupon(args);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(coupon, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_update_coupon',
    description: 'Update an existing coupon',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Coupon ID',
        },
        code: {
          type: 'string',
          description: 'Updated code',
        },
        discount: {
          type: 'string',
          description: 'Updated discount',
        },
        appointmentTypeIDs: {
          type: 'array',
          items: { type: 'number' },
          description: 'Updated appointment type IDs',
        },
        expirationDate: {
          type: 'string',
          description: 'Updated expiration date',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const { id, ...updateParams } = args;
      const coupon = await client.updateCoupon(id, updateParams);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(coupon, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_delete_coupon',
    description: 'Delete a coupon',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Coupon ID to delete',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      await client.deleteCoupon(args.id);
      return {
        content: [
          {
            type: 'text',
            text: `Coupon ${args.id} deleted successfully`,
          },
        ],
      };
    },
  },
];
