import dbConnect from "@/lib/mongodb";
import Store from "@/models/Store";
import { NextRequest, NextResponse } from "next/server";

export async function GET(request: NextRequest, context?: { params: Promise<any> }) {
  try {
    await dbConnect();
    const { searchParams } = new URL(request.url);
    const slug = context?.params ? (await context.params).slug : null;

    if (!slug) {
      return NextResponse.json({ success: false, error: "Store slug is required" }, { status: 400 });
    }

    const store = await Store.findOne({ slug, isActive: true });

    if (!store) {
      return NextResponse.json({ success: false, error: "Store not found" }, { status: 404 });
    }

    return NextResponse.json({ success: true, data: store });
  } catch (err: any) {
    console.error("Store details GET error", err);
    return NextResponse.json({ success: false, error: err.message || "Failed to fetch store details" }, { status: 500 });
  }
}   