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

export function createBenefitsTools(client: RipplingClient) {
  return {
    rippling_list_benefits_plans: {
      description: 'List all benefits plans',
      inputSchema: z.object({
        type: z.enum(['HEALTH', 'DENTAL', 'VISION', '401K', 'FSA', 'HSA', 'LIFE', 'DISABILITY', 'OTHER']).optional().describe('Filter by plan type'),
        isActive: z.boolean().optional().describe('Filter by active status'),
        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.listBenefitsPlans(args);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

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

    rippling_list_benefits_enrollments: {
      description: 'List benefits enrollments',
      inputSchema: z.object({
        employeeId: z.string().optional().describe('Filter by employee ID'),
        planId: z.string().optional().describe('Filter by plan ID'),
        status: z.enum(['ACTIVE', 'PENDING', 'TERMINATED', 'WAIVED']).optional().describe('Filter by enrollment status'),
        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.listBenefitsEnrollments(args);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

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