<?php
require_once '../config/db.php';

$sql = "
CREATE TABLE IF NOT EXISTS `laporan_warga` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `rumah_warga_id` INT(11) NOT NULL,
  `pelapor_id` INT(11) NOT NULL,
  `koordinator_ibadah_id` INT(11) NULL DEFAULT NULL,
  `jenis_laporan` ENUM(
    'data_tidak_sesuai',
    'warga_mampu',
    'warga_pindah',
    'warga_meninggal',
    'data_ganda',
    'lainnya'
  ) NOT NULL DEFAULT 'data_tidak_sesuai',
  `deskripsi` TEXT NOT NULL,
  `prioritas` ENUM('rendah', 'sedang', 'tinggi') NOT NULL DEFAULT 'sedang',
  `status` ENUM(
    'pending',
    'ditinjau',
    'diproses',
    'selesai',
    'ditolak'
  ) NOT NULL DEFAULT 'pending',
  `catatan_admin` TEXT NULL DEFAULT NULL,
  `ditugaskan_ke` VARCHAR(150) NULL DEFAULT NULL,
  `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
  `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP(),
  PRIMARY KEY (`id`),
  KEY `fk_laporan_warga` (`rumah_warga_id`),
  KEY `fk_laporan_pelapor` (`pelapor_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
";

try {
    $pdo->exec($sql);
    echo "Tabel laporan_warga berhasil dibuat!";
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
