USE kemiskinan_ibadah;

-- 1. Update USERS table role ENUM
ALTER TABLE users MODIFY COLUMN role ENUM('admin', 'operator', 'walikota') NOT NULL DEFAULT 'operator';

-- 2. Add walikota user (password: walikota123, hash generated previously or will generate)
-- Let's use the hash for 'walikota123': $2y$10$w6QO8q/s28pX83JgY3WvM.Hw2N2G1aN9M0iR8L7Pq4z8i5u0N72E. (Wait, let's just create a PHP script to insert to avoid hash issues)

-- 3. Modify KEMISKINAN table
ALTER TABLE kemiskinan 
ADD COLUMN tanggal_lahir DATE NULL AFTER nama_kk,
ADD COLUMN pendidikan VARCHAR(100) NULL AFTER tanggal_lahir,
ADD COLUMN riwayat_penyakit TEXT NULL AFTER pendidikan;

-- 4. Create LAPORAN_MASYARAKAT table
CREATE TABLE IF NOT EXISTS laporan_masyarakat (
  id INT AUTO_INCREMENT PRIMARY KEY,
  nama_pelapor VARCHAR(150) NOT NULL,
  kontak VARCHAR(50) NULL,
  deskripsi_laporan TEXT NOT NULL,
  lat DECIMAL(10,7) NOT NULL,
  lng DECIMAL(10,7) NOT NULL,
  foto VARCHAR(255) NULL,
  status ENUM('menunggu', 'diproses', 'selesai') NOT NULL DEFAULT 'menunggu',
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 5. Create HISTORI_BANTUAN table
CREATE TABLE IF NOT EXISTS histori_bantuan (
  id INT AUTO_INCREMENT PRIMARY KEY,
  kemiskinan_id INT NOT NULL,
  jenis_bantuan VARCHAR(150) NOT NULL,
  tanggal DATE NOT NULL,
  keterangan TEXT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (kemiskinan_id) REFERENCES kemiskinan(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
