import { SystemType } from './SystemSelector';

interface CommandResult {
  system: SystemType;
  endpoint: string;
  params?: Record<string, any>;
  courseId?: number;
}

export const parseCommand = (prompt: string, system: SystemType): CommandResult | null => {
  const lowerPrompt = prompt.toLowerCase().trim();

  if (system === 'canvas') {
    // Extract course ID if present (e.g., "get students in course 123")
    const courseIdMatch = lowerPrompt.match(/course\s+(\d+)/);
    const courseId = courseIdMatch ? parseInt(courseIdMatch[1], 10) : 1; // Default to 1 if not specified

    if (lowerPrompt.includes('get all students')) {
      return {
        system: 'canvas',
        endpoint: '/users',
        params: {
          enrollment_type: ['student'],
          per_page: 100
        },
        courseId
      };
    }

    if (lowerPrompt.includes('get courses')) {
      return {
        system: 'canvas',
        endpoint: '/courses',
        params: {
          per_page: 100
        }
      };
    }

    if (lowerPrompt.includes('get assignments')) {
      return {
        system: 'canvas',
        endpoint: '/assignments',
        params: {
          per_page: 100
        },
        courseId
      };
    }
  } else if (system === 'council') {
    if (lowerPrompt.includes('get all students')) {
      return {
        system: 'council',
        endpoint: '/students',
        params: {
          limit: 100
        }
      };
    }

    if (lowerPrompt.includes('get courses')) {
      return {
        system: 'council',
        endpoint: '/courses',
        params: {
          limit: 100
        }
      };
    }

    if (lowerPrompt.includes('get assignments')) {
      return {
        system: 'council',
        endpoint: '/assignments',
        params: {
          limit: 100
        }
      };
    }
  }

  return null;
}; 