import { CloverClient } from '../clients/clover.js';
import { CloverMerchant, CloverDevice, CloverTenderType } from '../types/index.js';

export function createMerchantsTools(client: CloverClient) {
  return {
    clover_get_merchant: {
      description: 'Get merchant information',
      inputSchema: {
        type: 'object',
        properties: {
          expand: {
            type: 'string',
            description: 'Comma-separated fields to expand (address, owner)',
          },
        },
      },
      handler: async (args: any) => {
        return await client.get<CloverMerchant>('', {
          expand: args.expand,
        });
      },
    },

    clover_update_merchant: {
      description: 'Update merchant settings',
      inputSchema: {
        type: 'object',
        properties: {
          name: { type: 'string', description: 'Merchant name' },
          phoneNumber: { type: 'string', description: 'Phone number' },
          website: { type: 'string', description: 'Website URL' },
        },
      },
      handler: async (args: any) => {
        return await client.post<CloverMerchant>('', args);
      },
    },

    clover_list_devices: {
      description: 'List all devices for the merchant',
      inputSchema: {
        type: 'object',
        properties: {
          expand: {
            type: 'string',
            description: 'Comma-separated fields to expand',
          },
        },
      },
      handler: async (args: any) => {
        const devices = await client.fetchPaginated<CloverDevice>(
          '/devices',
          { expand: args.expand }
        );
        return { devices, count: devices.length };
      },
    },

    clover_get_device: {
      description: 'Get a specific device by ID',
      inputSchema: {
        type: 'object',
        properties: {
          deviceId: { type: 'string', description: 'Device ID' },
        },
        required: ['deviceId'],
      },
      handler: async (args: any) => {
        return await client.get<CloverDevice>(`/devices/${args.deviceId}`);
      },
    },

    clover_list_tender_types: {
      description: 'List tender types (payment methods)',
      inputSchema: {
        type: 'object',
        properties: {},
      },
      handler: async () => {
        const tenders = await client.fetchPaginated<CloverTenderType>('/tenders');
        return { tenders, count: tenders.length };
      },
    },
  };
}
