import { defineConfig } from 'vite';

export default defineConfig({
    server: {
        proxy: {
            '/api/local': {
                target: 'http://localhost:3000',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/local/, '/api')
            },
            '/api/planning-data': {
                target: 'http://localhost:3000',
                changeOrigin: true
            },
            '/api/potential-data': {
                target: 'http://localhost:3000',
                changeOrigin: true
            },
            // -- WFS Proxies --
            '/api/wfs/linfos': {
                target: 'https://www.wfs.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wfs\/linfos/, '/umwelt/linfos'),
                secure: false
            },
            '/api/wfs/alkis': {
                target: 'https://www.wfs.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wfs\/alkis/, '/geobasis/wfs_nw_alkis_vereinfacht'),
                secure: false
            },
            '/api/wfs/roads': {
                target: 'https://www.wfs.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wfs\/roads/, '/wfs/DE_NW_SBV_INSPIRE_Downloadservice_Strassennetz'),
                secure: false
            },
            // Inspire Schutzgebiete (bisher genutzt)
            '/api/nrw/wfs': {
                target: 'https://www.wfs.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/nrw\/wfs/, '/umwelt/wfs_nw_inspire-schutzgebiete'),
                secure: false
            },
            // Aviation WFS (HaleConnect)
            '/api/wfs/aviation': {
                target: 'https://haleconnect.com',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wfs\/aviation/, '/ows/services/org.732.341f2791-919e-49de-8d86-3b18e040c430_wfs'),
                secure: false
            },

            // NRW Strassennetz WFS (Downloadservice)
            '/api/wfs/nrw_roads': {
                target: 'http://www.wfs.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wfs\/nrw_roads/, '/wfs/DE_NW_SBV_INSPIRE_Downloadservice_Strassennetz'),
                secure: false
            },

            // ATKIS Basis-DLM (Topographic data)
            '/api/wfs/atkis': {
                target: 'https://www.wfs.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wfs\/atkis/, '/geobasis/wfs_nw_inspire-verkehrsnetze_atkis-basis-dlm'),
                secure: false
            },

            // Flood Zones (Überschwemmungsgebiete) WMS
            '/api/wms/uesg_new': {
                target: 'https://www.wms.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wms\/uesg_new/, '/umwelt/wasser/uesg'),
                secure: false
            },

            // Renewable Energy WFS
            '/api/wfs/energy': {
                target: 'https://www.wfs.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wfs\/energy/, '/umwelt/erneuerbare_energien_wfs'),
                secure: false
            },

            // -- WMS Proxies (Bilder) --
            '/api/wms/dop': {
                target: 'https://www.wms.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wms\/dop/, '/geobasis/wms_nw_dop'),
                secure: false
            },
            '/api/wms/hu': { // Hausumringe
                target: 'https://www.wms.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wms\/hu/, '/geobasis/wms_nw_hu'),
                secure: false
            },
            '/api/wms/energy': { // Erneuerbare Energien
                target: 'https://www.wms.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wms\/energy/, '/umwelt/erneuerbare_energien_nrw'),
                secure: false
            },
            '/api/wms/wsg': { // Wasserschutzgebiete
                target: 'https://www.wms.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wms\/wsg/, '/umwelt/wasser/wsg'),
                secure: false
            },
            '/api/wfs/wsg': { // Wasserschutzgebiete WFS
                target: 'https://www.wfs.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wfs\/wsg/, '/umwelt/wasser/wsg'),
                secure: false
            },
            '/api/wms/roads': { // Strassen NRW Karten
                target: 'https://www.wms.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wms\/roads/, '/wms/strassen_nrw_karten'),
                secure: false
            },
            '/api/wms/linfos': { // LINFOS Visual
                target: 'https://www.wms.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wms\/linfos/, '/umwelt/linfos'),
                secure: false
            },
            '/api/wms/uesg': { // Überschwemmungsgebiete
                target: 'https://www.wms.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wms\/uesg/, '/umwelt/wasser/uesg'),
                secure: false
            },
            '/api/wms/alkis': { // ALKIS WMS
                target: 'https://www.wms.nrw.de',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api\/wms\/alkis/, '/geobasis/wms_nw_alkis'),
                secure: false
            }
        }
    }
});
