<?php
declare(strict_types=1);
define('ACC_BASE_PATH', __DIR__);
require __DIR__ . '/standalone/bootstrap.php';
global $wpdb;
$p = $wpdb->prefix;
echo json_encode([
    'districts' => (int)$wpdb->get_var("SELECT COUNT(*) FROM {$p}gis_districts"),
    'districts_list' => $wpdb->get_results("SELECT id,name,city,code FROM {$p}gis_districts ORDER BY id", ARRAY_A),
    'neighborhoods' => (int)$wpdb->get_var("SELECT COUNT(*) FROM {$p}gis_neighborhoods"),
    'sample_neighborhoods' => $wpdb->get_results("SELECT id,name,district_id FROM {$p}gis_neighborhoods ORDER BY district_id,id LIMIT 20", ARRAY_A),
    'parcels' => (int)$wpdb->get_var("SELECT COUNT(*) FROM {$p}gis_parcels"),
    'block_stats' => (int)$wpdb->get_var("SELECT COUNT(*) FROM {$p}gis_block_stats"),
    'melk_cases' => (int)$wpdb->get_var("SELECT COUNT(*) FROM {$p}melk_cases"),
    'melk_org' => (int)$wpdb->get_var("SELECT COUNT(*) FROM {$p}melk_org_assignments"),
    'melk_org_cols' => $wpdb->get_results("SHOW COLUMNS FROM {$p}melk_org_assignments", ARRAY_A),
    'sample_parcels' => $wpdb->get_results("SELECT id,code,block_code,district_id,neighborhood_id,status,area_sqm FROM {$p}gis_parcels WHERE district_id=1 AND neighborhood_id=1 AND block_code IS NOT NULL AND block_code!='' AND status!='archived' LIMIT 5", ARRAY_A),
    'sample_blocks' => $wpdb->get_results("SELECT block_code,district_id,neighborhood_id,total_parcels,cnt_building FROM {$p}gis_block_stats WHERE district_id=1 AND neighborhood_id=1 LIMIT 5", ARRAY_A),
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
