
import { NextRequest, NextResponse } from "next/server";
import db from "@/lib/db";

import { getLogger } from "@/utils/logger";

const logger = getLogger("/api/variants/[uuid]");

export const GET = async (req: NextRequest, { params }: { params: { uuid: string } }) => {
    try {


        const variantsUuid = params.uuid;

        const variant = await db.productVariant.findUnique({
            where: {
                uuid: variantsUuid as string,
            },
            include: {
                variant_images: true,
                product: true,
                Question: {
                    include: {
                        profile: true
                    }
                },
                Review: {
                    include: {
                        profile: true
                    }
                },
                _count: {
                    select: { Review: true }
                }
            },
    
        })

        return NextResponse.json({ mssg: variant }, { status: 200 });
    }
    catch (error:any) {
        logger.error(`Failed to fetch a variant of uuid ${params.uuid}`, {
            error: error?.config?.data ?? error?.message ?? "Unknown error"
        })
        return new NextResponse("Internal Server Error", { status: 500 });
    }
}