import { NextRequest } from 'next/server';

import { requestTaylor } from '@/app/api-utlities/clients/taylor.client';
import { createReviewMutation } from '@/app/api-utlities/requests/common';

import { reviewSchema } from '@/features/review-form/model/review-form.schema';

export const POST = async (req: NextRequest) => {
  const body = await req.json();

  const validatedRequest = reviewSchema.parse(body);

  await requestTaylor(
    { mutation: createReviewMutation },
    {
      review: {
        polnoeImya: validatedRequest.name,
        otzyv: validatedRequest.reviewMessage,
        rejting: validatedRequest.rating,
      },
    },
  );

  return new Response(JSON.stringify({ success: true }), {
    status: 201,
  });
};
