/**
 * Basecamp Uploads Tools (File Uploads)
 */

import { BasecampClient } from '../clients/basecamp.js';
import type { Upload } from '../types/index.js';

export function registerUploadsTools(client: BasecampClient) {
  return [
    {
      name: 'basecamp_uploads_list',
      description: 'List all uploads in a vault',
      inputSchema: {
        type: 'object',
        properties: {
          project_id: {
            type: 'number',
            description: 'The ID of the project',
          },
          vault_id: {
            type: 'number',
            description: 'The ID of the vault',
          },
          status: {
            type: 'string',
            enum: ['active', 'archived', 'trashed'],
            description: 'Filter by status',
          },
        },
        required: ['project_id', 'vault_id'],
      },
      handler: async (args: { project_id: number; vault_id: number; status?: string }) => {
        const { data } = await client.get<Upload[]>(
          `/buckets/${args.project_id}/vaults/${args.vault_id}/uploads.json`,
          args.status ? { status: args.status } : undefined
        );
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(data, null, 2),
            },
          ],
        };
      },
    },

    {
      name: 'basecamp_upload_get',
      description: 'Get a specific upload by ID',
      inputSchema: {
        type: 'object',
        properties: {
          project_id: {
            type: 'number',
            description: 'The ID of the project',
          },
          upload_id: {
            type: 'number',
            description: 'The ID of the upload',
          },
        },
        required: ['project_id', 'upload_id'],
      },
      handler: async (args: { project_id: number; upload_id: number }) => {
        const { data } = await client.get<Upload>(
          `/buckets/${args.project_id}/uploads/${args.upload_id}.json`
        );
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(data, null, 2),
            },
          ],
        };
      },
    },

    {
      name: 'basecamp_upload_create',
      description: 'Upload a file to a vault (Note: Requires multipart/form-data, may need special handling)',
      inputSchema: {
        type: 'object',
        properties: {
          project_id: {
            type: 'number',
            description: 'The ID of the project',
          },
          vault_id: {
            type: 'number',
            description: 'The ID of the vault',
          },
          description: {
            type: 'string',
            description: 'File description/caption',
          },
        },
        required: ['project_id', 'vault_id'],
      },
      handler: async (args: { project_id: number; vault_id: number; description?: string }) => {
        // Note: File upload requires special handling - this is a placeholder
        // In practice, you'd need to handle the file binary data
        return {
          content: [
            {
              type: 'text',
              text: 'File upload requires multipart/form-data handling. Use the Basecamp API directly or upload via web UI.',
            },
          ],
        };
      },
    },
  ];
}
