export async function seedReferensi(connection) {
	await connection.query(`
		CREATE TABLE IF NOT EXISTS ref_kategori_warung (
			id INT AUTO_INCREMENT PRIMARY KEY,
			kode VARCHAR(30) NOT NULL UNIQUE,
			nama VARCHAR(50) NOT NULL,
			icon VARCHAR(10) NOT NULL DEFAULT '📦',
			urutan INT NOT NULL DEFAULT 0,
			is_aktif TINYINT(1) NOT NULL DEFAULT 1
		) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
	`);

	await connection.query(`
		CREATE TABLE IF NOT EXISTS ref_hari_buka (
			id INT AUTO_INCREMENT PRIMARY KEY,
			kode VARCHAR(30) NOT NULL UNIQUE,
			label VARCHAR(50) NOT NULL,
			urutan INT NOT NULL DEFAULT 0,
			is_aktif TINYINT(1) NOT NULL DEFAULT 1
		) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
	`);

	const kategoriSeed = [
		['jajanan', 'Jajanan', '🍿', 1],
		['makanan', 'Makanan', '🍚', 2],
		['minuman', 'Minuman', '🥤', 3],
		['sembako', 'Sembako', '🛒', 4],
		['kelontong', 'Kelontong', '🏪', 5],
		['campuran', 'Campuran', '📦', 6]
	];

	for (const [kode, nama, icon, urutan] of kategoriSeed) {
		await connection.query(
			`INSERT INTO ref_kategori_warung (kode, nama, icon, urutan)
			 VALUES (?, ?, ?, ?)
			 ON DUPLICATE KEY UPDATE nama = VALUES(nama), icon = VALUES(icon), urutan = VALUES(urutan)`,
			[kode, nama, icon, urutan]
		);
	}

	const hariBukaSeed = [
		['senin-minggu', 'Senin-Minggu', 1],
		['senin-sabtu', 'Senin-Sabtu', 2],
		['senin-jumat', 'Senin-Jumat', 3],
		['sabtu-minggu', 'Sabtu-Minggu', 4]
	];

	for (const [kode, label, urutan] of hariBukaSeed) {
		await connection.query(
			`INSERT INTO ref_hari_buka (kode, label, urutan)
			 VALUES (?, ?, ?)
			 ON DUPLICATE KEY UPDATE label = VALUES(label), urutan = VALUES(urutan)`,
			[kode, label, urutan]
		);
	}
}
