import * as sheet from '$lib/helpers/sheets'
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import * as pb from "$lib/helpers/pb"
export const GET: RequestHandler = async () => {

  const res = await sheet.getData();

  return json(res);

}

export const POST: RequestHandler = async ({ request }) => {

  const body = await request.json();
  console.log(body)
  try {
    await sheet.addPerson({ name: body.name, confidence: body.confidence.toString(), noble_name: body.adelsTitel })

    await pb.createPerson({
      name: body.name,
      confidence: body.confidence,
      noble_name: body.adelsTitel,
      portrait: body.portraitUrl,
      hair_length: body.portraitHairLength,
      hair_type: body.portraitHairType,
      hair_color: body.portraitHairColor,
      portrait_public: body.portraitPublic,
      skin_color: body.portraitSkinColor,
    });
  } catch (e) {
    console.log(e)
  }

  return json(body);
}
