/**
 * BigCommerce Channels Tools
 */

import { BigCommerceClient } from '../clients/bigcommerce.js';

export function registerChannelsTools(client: BigCommerceClient) {
  return [
    {
      name: 'bigcommerce_list_channels',
      description: 'List all sales channels (storefronts, marketplaces, POS, etc.)',
      inputSchema: {
        type: 'object',
        properties: {
          type: { 
            type: 'string',
            enum: ['storefront', 'pos', 'marketplace', 'marketing'],
            description: 'Filter by channel type' 
          },
          platform: { type: 'string', description: 'Filter by platform name' },
        },
      },
      handler: async (args: any) => {
        const channels = await client.get(`/channels?${new URLSearchParams(args).toString()}`);
        return { content: [{ type: 'text', text: JSON.stringify(channels, null, 2) }] };
      },
    },
    {
      name: 'bigcommerce_get_channel',
      description: 'Get detailed information about a specific channel',
      inputSchema: {
        type: 'object',
        properties: {
          channel_id: { type: 'number', description: 'Channel ID' },
        },
        required: ['channel_id'],
      },
      handler: async (args: any) => {
        const channel = await client.get(`/channels/${args.channel_id}`);
        return { content: [{ type: 'text', text: JSON.stringify(channel, null, 2) }] };
      },
    },
    {
      name: 'bigcommerce_list_channel_listings',
      description: 'List product listings for a specific channel',
      inputSchema: {
        type: 'object',
        properties: {
          channel_id: { type: 'number', description: 'Channel ID' },
          product_id: { type: 'number', description: 'Filter by product ID' },
        },
        required: ['channel_id'],
      },
      handler: async (args: any) => {
        const { channel_id, ...params } = args;
        const queryParams = new URLSearchParams(params);
        const listings = await client.get<any>(`/channels/${channel_id}/listings?${queryParams.toString()}`);
        return { content: [{ type: 'text', text: JSON.stringify(listings, null, 2) }] };
      },
    },
  ];
}
