CREATE DATABASE IF NOT EXISTS webgis_pontianak;
USE webgis_pontianak;

CREATE TABLE admins (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL UNIQUE,
    password VARCHAR(255) NOT NULL
) ENGINE=InnoDB;

INSERT INTO admins (username, password) VALUES
('admin', '$2y$10$g356t75x6pjEidqWWu3yaOR7H3eBUaZJ5QY47DAP61EHzJvnJBT8a');

CREATE TABLE poor_residents (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    nik VARCHAR(16) DEFAULT NULL,
    family_size INT NOT NULL DEFAULT 1,
    income INT NOT NULL DEFAULT 0,
    rt_rw VARCHAR(20) DEFAULT NULL,
    lat DOUBLE NOT NULL,
    lng DOUBLE NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB;

INSERT INTO poor_residents (name, nik, family_size, income, rt_rw, lat, lng) VALUES
('Rahmat Hidayat', '6171012345670001', 4, 750000, '002/003', -0.048, 109.325),
('Siti Maryam', '6171012345670002', 5, 600000, '001/002', -0.055, 109.332),
('Budi Gunawan', '6171012345670003', 3, 900000, '004/001', -0.042, 109.345),
('Dewi Sartika', '6171012345670004', 6, 480000, '003/005', -0.048, 109.355),
('Eko Widodo', '6171012345670005', 4, 820000, '005/002', -0.040, 109.310),
('Fitriani', '6171012345670006', 3, 1100000, '002/004', -0.058, 109.338),
('Gunadi', '6171012345670007', 7, 350000, '001/001', -0.052, 109.360),
('Hesti Nuraini', '6171012345670008', 2, 1200000, '006/003', -0.035, 109.318);

-- Tabel pengaturan
CREATE TABLE settings (
    setting_key VARCHAR(50) PRIMARY KEY,
    setting_value TEXT NOT NULL
) ENGINE=InnoDB;

INSERT INTO settings (setting_key, setting_value) VALUES ('buffer_radius', '500');