-- Tabel SPBU (Point)
CREATE TABLE `spbu` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `namaspbu` varchar(150) NOT NULL,
  `nomorwa` varchar(20) DEFAULT NULL,
  `statusbuka` enum('full','limited') DEFAULT 'limited',
  `koordinat` JSON DEFAULT NULL COMMENT 'GeoJSON Point',
  `lat` decimal(10,8) GENERATED ALWAYS AS (JSON_EXTRACT(`koordinat`, '$.coordinates[1]')) STORED,
  `lng` decimal(11,8) GENERATED ALWAYS AS (JSON_EXTRACT(`koordinat`, '$.coordinates[0]')) STORED,
  `createdat` timestamp NOT NULL DEFAULT current_timestamp(),
  `updatedat` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- Tabel Jalan (Polyline)
CREATE TABLE `jalan` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `nama` varchar(150) NOT NULL,
  `status` enum('nasional','provinsi','kabupaten') NOT NULL DEFAULT 'kabupaten',
  `panjang_meter` decimal(12,2) DEFAULT NULL,
  `geom` JSON NOT NULL COMMENT 'GeoJSON LineString',
  `createdat` timestamp NOT NULL DEFAULT current_timestamp(),
  `updatedat` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- Tabel Parsil Tanah (Polygon)
CREATE TABLE `parsil` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `nama` varchar(150) NOT NULL,
  `status_kepemilikan` enum('SHM','HGB','HGU','HP') NOT NULL DEFAULT 'SHM',
  `luas_m2` decimal(14,2) DEFAULT NULL,
  `geom` JSON NOT NULL COMMENT 'GeoJSON Polygon',
  `createdat` timestamp NOT NULL DEFAULT current_timestamp(),
  `updatedat` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;