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

export function createCompaniesTools(client: RipplingClient) {
  return {
    rippling_get_company: {
      description: 'Get company information',
      inputSchema: z.object({}),
      handler: async () => {
        const result = await client.getCompany();
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    rippling_list_departments: {
      description: 'List all departments',
      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.listDepartments(args);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    rippling_create_department: {
      description: 'Create a new department',
      inputSchema: z.object({
        name: z.string().describe('Department name'),
        parentId: z.string().optional().describe('Parent department ID'),
        headId: z.string().optional().describe('Department head employee ID'),
      }),
      handler: async (args: any) => {
        const result = await client.createDepartment(args);
        return {
          content: [
            {
              type: 'text',
              text: `Department created successfully:\n${JSON.stringify(result, null, 2)}`,
            },
          ],
        };
      },
    },

    rippling_list_locations: {
      description: 'List all work locations',
      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.listLocations(args);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    rippling_list_teams: {
      description: 'List all teams',
      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.listTeams(args);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },
  };
}
