CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL,
  `password` varchar(255) NOT NULL,
  `role` enum('admin','guru','siswa') NOT NULL,
  `nama_lengkap` varchar(100) DEFAULT NULL,
  `nomor_induk` varchar(20) DEFAULT NULL,
  `nomor_wa_orang_tua` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `izin` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `tanggal_izin` datetime NOT NULL,
  `alasan` text NOT NULL,
  `status` enum('menunggu','disetujui','ditolak','selesai') NOT NULL DEFAULT 'menunggu',
  `guru_id` int(11) DEFAULT NULL,
  `admin_id` int(11) DEFAULT NULL,
  `waktu_kembali` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  CONSTRAINT `izin_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `log_aktivitas` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) DEFAULT NULL,
  `aktivitas` varchar(255) NOT NULL,
  `timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Data Dummy
INSERT INTO `users` (`id`, `username`, `password`, `role`, `nama_lengkap`, `nomor_induk`) VALUES
(1, 'admin1', '$2y$10$g.g.j.Z.d.2...//..//..//..//..//..//..//..//..//..//', 'admin', 'Admin Satu', NULL),
(2, 'admin2', '$2y$10$g.g.j.Z.d.2...//..//..//..//..//..//..//..//..//..//', 'admin', 'Admin Dua', NULL),
(3, '1001', '$2y$10$g.g.j.Z.d.2...//..//..//..//..//..//..//..//..//..//', 'siswa', 'Siswa Satu', '1001'),
(4, '1002', '$2y$10$g.g.j.Z.d.2...//..//..//..//..//..//..//..//..//..//', 'siswa', 'Siswa Dua', '1002'),
(5, '1003', '$2y$10$g.g.j.Z.d.2...//..//..//..//..//..//..//..//..//..//', 'siswa', 'Siswa Tiga', '1003'),
(6, 'guru1', '$2y$10$g.g.j.Z.d.2...//..//..//..//..//..//..//..//..//..//', 'guru', 'Guru Satu', NULL);

INSERT INTO `izin` (`id`, `user_id`, `tanggal_izin`, `alasan`, `status`, `guru_id`, `admin_id`, `waktu_kembali`) VALUES
(1, 3, '2025-10-23 10:00:00', 'Sakit gigi', 'disetujui', 6, 1, NULL),
(2, 4, '2025-10-23 11:00:00', 'Keperluan keluarga', 'menunggu', NULL, NULL, NULL),
(3, 5, '2025-10-23 09:30:00', 'Ada urusan mendadak', 'ditolak', NULL, 2, NULL),
(4, 3, '2025-10-22 14:00:00', 'Pulang lebih awal', 'selesai', 6, 1, '2025-10-22 15:00:00'),
(5, 4, '2025-10-24 08:00:00', 'Mengikuti lomba', 'menunggu', NULL, NULL, NULL);
