// import fetch from 'node-fetch';

async function checkCaps() {
    try {
        console.log("Checking Inspire Sites Caps...");
        const url = "https://www.wms.nrw.de/umwelt/wfs_nw_inspire-schutzgebiete?REQUEST=GetCapabilities&SERVICE=WMS";
        const res = await fetch(url);
        const text = await res.text();
        console.log("Length:", text.length);

        // formats
        if (text.includes('Layer')) {
            const layers = text.match(/<Name>(.*?)<\/Name>/g);
            // Log first 20 layers
            if (layers) console.log("Layers:", layers.slice(0, 20));
        }
        // Switch back to WMS linfos URL
        const url2 = "https://www.wms.nrw.de/umwelt/linfos?REQUEST=GetCapabilities&SERVICE=WMS";
        const res2 = await fetch(url2);
        const text2 = await res2.text();
        if (text2.includes('Layer')) {
            const layers = text2.match(/<Name>(.*?)<\/Name>/g);
            if (layers) console.log("LINFOS Layers:", layers.slice(0, 20));
        }
        if (text.includes('outputFormat')) {
            // Basic regex to find outputFormat block
            const match = text.match(/name="outputFormat"[\s\S]*?<\/ows:Parameter>/);
            if (match) {
                console.log("OutputFormats Block:", match[0]);
            } else {
                console.log("No specific outputFormat parameter found in typical place.");
                // Look for other indicators
                const jsonRef = text.match(/json/i);
                console.log("JSON Keywords:", jsonRef);
            }
        } else {
            console.log("No outputFormat string found.");
        }

    } catch (e) {
        console.error(e);
    }
}

checkCaps();
