/**
 * BigCommerce Brands Tools
 */

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

export function registerBrandsTools(client: BigCommerceClient) {
  return [
    {
      name: 'bigcommerce_list_brands',
      description: 'List all brands from BigCommerce store with optional filters',
      inputSchema: {
        type: 'object',
        properties: {
          name: { type: 'string', description: 'Filter by brand name' },
          page_title: { type: 'string', description: 'Filter by page title' },
        },
      },
      handler: async (args: any) => {
        const params = new URLSearchParams(args);
        const brands = await client.get<any>(`/catalog/brands?${params.toString()}`);
        return { content: [{ type: 'text', text: JSON.stringify(brands, null, 2) }] };
      },
    },
    {
      name: 'bigcommerce_get_brand',
      description: 'Get detailed information about a specific brand',
      inputSchema: {
        type: 'object',
        properties: {
          brand_id: { type: 'number', description: 'Brand ID' },
        },
        required: ['brand_id'],
      },
      handler: async (args: any) => {
        const brand = await client.get<any>(`/catalog/brands/${args.brand_id}`);
        return { content: [{ type: 'text', text: JSON.stringify(brand, null, 2) }] };
      },
    },
    {
      name: 'bigcommerce_create_brand',
      description: 'Create a new brand in BigCommerce',
      inputSchema: {
        type: 'object',
        properties: {
          name: { type: 'string', description: 'Brand name' },
          page_title: { type: 'string', description: 'Page title for SEO' },
          meta_keywords: { 
            type: 'array', 
            items: { type: 'string' },
            description: 'Meta keywords for SEO' 
          },
          meta_description: { type: 'string', description: 'Meta description for SEO' },
          image_url: { type: 'string', description: 'Brand logo/image URL' },
          search_keywords: { type: 'string', description: 'Search keywords' },
        },
        required: ['name'],
      },
      handler: async (args: any) => {
        const brand = await client.post<any>('/catalog/brands', args);
        return { content: [{ type: 'text', text: JSON.stringify(brand, null, 2) }] };
      },
    },
    {
      name: 'bigcommerce_update_brand',
      description: 'Update an existing brand',
      inputSchema: {
        type: 'object',
        properties: {
          brand_id: { type: 'number', description: 'Brand ID' },
          name: { type: 'string', description: 'Brand name' },
          page_title: { type: 'string', description: 'Page title for SEO' },
          meta_keywords: { 
            type: 'array', 
            items: { type: 'string' },
            description: 'Meta keywords for SEO' 
          },
          meta_description: { type: 'string', description: 'Meta description for SEO' },
          image_url: { type: 'string', description: 'Brand logo/image URL' },
          search_keywords: { type: 'string', description: 'Search keywords' },
        },
        required: ['brand_id'],
      },
      handler: async (args: any) => {
        const { brand_id, ...updateData } = args;
        const brand = await client.put<any>(`/catalog/brands/${brand_id}`, updateData);
        return { content: [{ type: 'text', text: JSON.stringify(brand, null, 2) }] };
      },
    },
    {
      name: 'bigcommerce_delete_brand',
      description: 'Delete a brand from BigCommerce',
      inputSchema: {
        type: 'object',
        properties: {
          brand_id: { type: 'number', description: 'Brand ID to delete' },
        },
        required: ['brand_id'],
      },
      handler: async (args: any) => {
        await client.delete<any>(`/catalog/brands/${args.brand_id}`);
        return { content: [{ type: 'text', text: `Brand ${args.brand_id} deleted successfully` }] };
      },
    },
  ];
}
