// src/pages/api/range/check-address.js (przykładowa nazwa)
import { getDb } from "../db.js";

export async function POST({ request }) {
  const { city, street, number } = await request.json();

  const db = getDb();

  const row = db
    .prepare(
      `SELECT *
         FROM ranges
        WHERE LOWER(city)   = LOWER(?)
          AND LOWER(street) = LOWER(?)
          AND LOWER(number) = LOWER(?)
        LIMIT 1`
    )
    .get(city, street || "", number || "");

  if (!row) {
    return new Response(JSON.stringify({ ok: false }), {
      headers: { "Content-Type": "application/json; charset=utf-8" },
    });
  }

  return new Response(JSON.stringify({ ok: true, result: row }), {
    headers: { "Content-Type": "application/json; charset=utf-8" },
  });
}
