import { NextResponse } from "next/server";
import { getServerSession } from "next-auth";

import prismadb from "@/lib/prisma";

const corsHeaders = {
  "Access-Control-Allow-Origin": "*",
  "Access-Control-Allow-Methods": "GET",
  "Access-Control-Allow-Headers": "Content-Type, Authorization",
};

export async function GET(
  req: Request,
  { params }: { params: { storeId: string } }
) {
  try {

    if (!params.storeId) {
      return new NextResponse("Boutique requise", { status: 400, headers: corsHeaders });
    }

    const store = await prismadb.store.findFirst({
      where: {
        id: params.storeId,
      },
      select: {
        name: true,
        logo: true,
        shopMail: true,
        shopPhone: true,
        shopUrl: true
      }
    });

    return NextResponse.json(store, { headers: corsHeaders });

  } catch (error) {
    console.log('[STORE_GET]', error);
    return new NextResponse("Internal error", { status: 500, headers: corsHeaders })
  }

};
