import { optima } from "$lib";
import { json } from "@sveltejs/kit";
import type { RequestHandler } from "./$types";

export const GET: RequestHandler = async ({ locals }) => {
  const accessToken = locals.session?.accessToken;
  if (!accessToken) {
    return json({ data: [] }, { status: 401 });
  }

  try {
    const members = await optima.cw.fetchMembers(accessToken);
    return json({ data: members });
  } catch (err) {
    console.error("[api/cw/members] Failed:", err);
    return json({ data: [] }, { status: 500 });
  }
};
