/**
 * Basecamp Campfires Tools (Chat)
 */

import { BasecampClient } from '../clients/basecamp.js';
import type { CampfireLine, CreateCampfireLineRequest } from '../types/index.js';

export function registerCampfiresTools(client: BasecampClient) {
  return [
    {
      name: 'basecamp_campfire_lines_list',
      description: 'List recent chat lines in a campfire',
      inputSchema: {
        type: 'object',
        properties: {
          project_id: {
            type: 'number',
            description: 'The ID of the project',
          },
          campfire_id: {
            type: 'number',
            description: 'The ID of the campfire',
          },
        },
        required: ['project_id', 'campfire_id'],
      },
      handler: async (args: { project_id: number; campfire_id: number }) => {
        const { data } = await client.get<CampfireLine[]>(
          `/buckets/${args.project_id}/chats/${args.campfire_id}/lines.json`
        );
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(data, null, 2),
            },
          ],
        };
      },
    },

    {
      name: 'basecamp_campfire_line_create',
      description: 'Send a chat message to campfire',
      inputSchema: {
        type: 'object',
        properties: {
          project_id: {
            type: 'number',
            description: 'The ID of the project',
          },
          campfire_id: {
            type: 'number',
            description: 'The ID of the campfire',
          },
          content: {
            type: 'string',
            description: 'The chat message content',
          },
        },
        required: ['project_id', 'campfire_id', 'content'],
      },
      handler: async (args: { project_id: number; campfire_id: number } & CreateCampfireLineRequest) => {
        const { project_id, campfire_id, ...payload } = args;
        const data = await client.post<CampfireLine>(
          `/buckets/${project_id}/chats/${campfire_id}/lines.json`,
          payload
        );
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(data, null, 2),
            },
          ],
        };
      },
    },
  ];
}
