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

export function createPayrollTools(client: RipplingClient) {
  return {
    rippling_list_pay_runs: {
      description: 'List all payroll runs',
      inputSchema: z.object({
        status: z.enum(['DRAFT', 'APPROVED', 'PROCESSING', 'COMPLETED', 'CANCELLED']).optional().describe('Filter by status'),
        startDate: z.string().optional().describe('Filter by start date (YYYY-MM-DD)'),
        endDate: z.string().optional().describe('Filter by end date (YYYY-MM-DD)'),
        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.listPayRuns(args);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    rippling_get_pay_run: {
      description: 'Get detailed information about a specific pay run',
      inputSchema: z.object({
        id: z.string().describe('Pay run ID'),
      }),
      handler: async (args: any) => {
        const result = await client.getPayRun(args.id);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    rippling_list_pay_statements: {
      description: 'List pay statements (paystubs)',
      inputSchema: z.object({
        employeeId: z.string().optional().describe('Filter by employee ID'),
        payRunId: z.string().optional().describe('Filter by pay run 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.listPayStatements(args);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    rippling_get_pay_statement: {
      description: 'Get detailed pay statement with earnings, taxes, and deductions',
      inputSchema: z.object({
        id: z.string().describe('Pay statement ID'),
      }),
      handler: async (args: any) => {
        const result = await client.getPayStatement(args.id);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },
  };
}
