import { z } from 'zod';
import type { RipplingClient } from '../clients/rippling.js';

export function createDevicesTools(client: RipplingClient) {
  return {
    rippling_list_devices: {
      description: 'List all devices (laptops, phones, etc.)',
      inputSchema: z.object({
        type: z.enum(['LAPTOP', 'DESKTOP', 'PHONE', 'TABLET', 'OTHER']).optional().describe('Filter by device type'),
        status: z.enum(['AVAILABLE', 'ASSIGNED', 'REPAIR', 'RETIRED']).optional().describe('Filter by status'),
        assignedTo: z.string().optional().describe('Filter by assigned employee ID'),
        cursor: z.string().optional().describe('Pagination cursor'),
        limit: z.number().min(1).max(500).default(100).optional().describe('Number of results per page'),
      }),
      handler: async (args: any) => {
        const result = await client.listDevices(args);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    rippling_get_device: {
      description: 'Get detailed device information',
      inputSchema: z.object({
        id: z.string().describe('Device ID'),
      }),
      handler: async (args: any) => {
        const result = await client.getDevice(args.id);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    rippling_list_apps: {
      description: 'List all app licenses and software',
      inputSchema: z.object({
        cursor: z.string().optional().describe('Pagination cursor'),
        limit: z.number().min(1).max(500).default(100).optional().describe('Number of results per page'),
      }),
      handler: async (args: any) => {
        const result = await client.listApps(args);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    rippling_get_app: {
      description: 'Get detailed app/license information',
      inputSchema: z.object({
        id: z.string().describe('App ID'),
      }),
      handler: async (args: any) => {
        const result = await client.getApp(args.id);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },
  };
}
