-- Create database if it does not exist
CREATE DATABASE IF NOT EXISTS spbu_db;
USE spbu_db;

-- 1. Create tb_jalan table (for road coordinates and metadata)
CREATE TABLE IF NOT EXISTS tb_jalan (
    id INT AUTO_INCREMENT PRIMARY KEY,
    nama_jalan VARCHAR(255) NOT NULL,
    status_jalan ENUM('Jalan Nasional', 'Jalan Provinsi', 'Jalan Kabupaten') NOT NULL,
    panjang_meter DOUBLE NOT NULL DEFAULT 0,
    koordinat JSON NOT NULL,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

-- 2. Create tb_parsil table (for land coordinates and ownership metadata)
CREATE TABLE IF NOT EXISTS tb_parsil (
    id INT AUTO_INCREMENT PRIMARY KEY,
    nama_pemilik VARCHAR(255) NOT NULL,
    status_kepemilikan ENUM('SHM', 'HGB', 'HGU', 'HP') NOT NULL,
    luas_m2 DOUBLE NOT NULL DEFAULT 0,
    koordinat JSON NOT NULL,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

-- 3. Create SPBU table (for gas station coordinates and metadata)
CREATE TABLE IF NOT EXISTS SPBU (
    id INT AUTO_INCREMENT PRIMARY KEY,
    nama VARCHAR(255) NOT NULL,
    nomor VARCHAR(255) NOT NULL,
    status VARCHAR(255) NOT NULL,
    Latitude DOUBLE NOT NULL,
    Longitude DOUBLE NOT NULL,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
