import { NextResponse } from 'next/server';
import { getSession } from '@/lib/session';

// Send password reset email to current user
// NOTE: WorkOS AuthKit handles password reset through the hosted UI flow
// Users can reset their password by clicking "Forgot password" on the login page
export async function POST() {
    try {
        const session = await getSession();
        if (!session?.user) {
            return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
        }

        // For WorkOS AuthKit, password reset is handled through the hosted UI
        // The user should be directed to re-authenticate via the login page
        // where they can click "Forgot password"

        // Return a message directing the user to the login page
        return NextResponse.json({
            success: true,
            message: 'To reset your password, please log out and use the "Forgot Password" option on the login page.',
            redirectTo: '/login'
        });
    } catch (error) {
        console.error('Password reset error:', error);
        return NextResponse.json({
            error: 'An error occurred. Please try again.'
        }, { status: 500 });
    }
}
