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

export function createLearningTools(client: RipplingClient) {
  return {
    rippling_list_courses: {
      description: 'List all training courses',
      inputSchema: z.object({
        category: z.string().optional().describe('Filter by category'),
        isRequired: z.boolean().optional().describe('Filter by required 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.listCourses(args);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

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

    rippling_list_course_assignments: {
      description: 'List course assignments',
      inputSchema: z.object({
        employeeId: z.string().optional().describe('Filter by employee ID'),
        courseId: z.string().optional().describe('Filter by course ID'),
        status: z.enum(['NOT_STARTED', 'IN_PROGRESS', 'COMPLETED', 'OVERDUE']).optional().describe('Filter by 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.listCourseAssignments(args);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    rippling_assign_course: {
      description: 'Assign a course to an employee',
      inputSchema: z.object({
        employeeId: z.string().describe('Employee ID'),
        courseId: z.string().describe('Course ID'),
        dueDate: z.string().optional().describe('Due date (YYYY-MM-DD)'),
      }),
      handler: async (args: any) => {
        const result = await client.assignCourse(args);
        return {
          content: [
            {
              type: 'text',
              text: `Course assigned successfully:\n${JSON.stringify(result, null, 2)}`,
            },
          ],
        };
      },
    },
  };
}
