/**
 * HubSpot Campaigns Tools
 * Tools for managing marketing campaigns
 */

import type { HubSpotClient } from '../clients/hubspot.js';

export function getTools(client: HubSpotClient) {
  return [
    {
      name: 'hubspot_list_campaigns',
      description: 'List all marketing campaigns',
      inputSchema: {
        type: 'object',
        properties: {
          limit: {
            type: 'number',
            description: 'Maximum number of campaigns to return',
            default: 20,
          },
          offset: {
            type: 'number',
            description: 'Offset for pagination',
            default: 0,
          },
        },
      },
      handler: async (args: any) => {
        const response = await client.apiRequest<any>({
          method: 'GET',
          url: '/marketing/v3/campaigns',
          params: {
            limit: args.limit || 20,
            offset: args.offset || 0,
          },
        });

        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(response, null, 2),
            },
          ],
        };
      },
    },

    {
      name: 'hubspot_get_campaign',
      description: 'Get a specific campaign by ID',
      inputSchema: {
        type: 'object',
        properties: {
          campaignId: {
            type: 'string',
            description: 'Campaign ID',
          },
        },
        required: ['campaignId'],
      },
      handler: async (args: any) => {
        const campaign = await client.apiRequest<any>({
          method: 'GET',
          url: `/marketing/v3/campaigns/${args.campaignId}`,
        });

        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(campaign, null, 2),
            },
          ],
        };
      },
    },

    {
      name: 'hubspot_create_campaign',
      description: 'Create a new marketing campaign',
      inputSchema: {
        type: 'object',
        properties: {
          name: {
            type: 'string',
            description: 'Campaign name',
          },
        },
        required: ['name'],
      },
      handler: async (args: any) => {
        const campaign = await client.apiRequest<any>({
          method: 'POST',
          url: '/marketing/v3/campaigns',
          data: {
            name: args.name,
          },
        });

        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  success: true,
                  campaignId: campaign.id,
                  campaign,
                },
                null,
                2
              ),
            },
          ],
        };
      },
    },

    {
      name: 'hubspot_update_campaign',
      description: 'Update an existing campaign',
      inputSchema: {
        type: 'object',
        properties: {
          campaignId: {
            type: 'string',
            description: 'Campaign ID',
          },
          name: {
            type: 'string',
            description: 'Updated campaign name',
          },
        },
        required: ['campaignId'],
      },
      handler: async (args: any) => {
        const campaign = await client.apiRequest<any>({
          method: 'PATCH',
          url: `/marketing/v3/campaigns/${args.campaignId}`,
          data: {
            name: args.name,
          },
        });

        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(
                {
                  success: true,
                  campaign,
                },
                null,
                2
              ),
            },
          ],
        };
      },
    },

    {
      name: 'hubspot_get_campaign_stats',
      description: 'Get statistics for a campaign (performance metrics)',
      inputSchema: {
        type: 'object',
        properties: {
          campaignId: {
            type: 'string',
            description: 'Campaign ID',
          },
        },
        required: ['campaignId'],
      },
      handler: async (args: any) => {
        const stats = await client.apiRequest<any>({
          method: 'GET',
          url: `/marketing/v3/campaigns/${args.campaignId}/statistics`,
        });

        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(stats, null, 2),
            },
          ],
        };
      },
    },
  ];
}
