/**
 * Trigger Schedule API
 * Manually trigger a scheduled sync
 */

import { NextRequest, NextResponse } from 'next/server';
import { syncScheduler } from '@/lib/services/sync-scheduler';

/**
 * POST /api/sync/schedules/[id]/trigger
 * Manually trigger a schedule
 */
export async function POST(
  request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  try {
    const { id } = await params;
    await syncScheduler.triggerSchedule(id);
    
    return NextResponse.json({
      success: true,
      message: 'Schedule triggered successfully',
    });
  } catch (error) {
    const errorMessage = error instanceof Error ? error.message : String(error);
    console.error('[TRIGGER API] Error triggering schedule:', errorMessage);
    
    return NextResponse.json(
      { error: 'Failed to trigger schedule', details: errorMessage },
      { status: 500 }
    );
  }
}
