<?php
include('c:/laragon/www/api_koneksi/config/koneksi.php');
include('c:/laragon/www/api_koneksi/config/id_generator.php');

// 1. Nonaktifkan semua paket lama
$conn->query("UPDATE mst_paket SET active_st = 0");

// 2. Insert Paket Baru
$pakets = [
    ['Couple ArtBox Studio', 'ArtBox', 'Harga Normal Rp. 100.000', "30 Minutes of Self Portrait\nMax 2 People\nFree to Choose Property\nFree Digital Soft Copy\nFree 2 Printed Photo (Promo)", 30, 50000, 'koneksi1'],
    ['Group ArtBox Studio', 'ArtBox', 'Harga Normal Rp. 105.000', "30 Minutes of Self Portrait\nMin 3 Orang\nRp. 19.000/Orang\nFree to Choose Property\nFree Digital Soft Copy\nFree 2 Printed Photo (Promo)", 30, 105000, 'koneksi2'],
    ['Couple GrayscaleBox', 'Grayscale', 'Harga Normal Rp. 100.000', "30 Minutes of Self Portrait\nMax 2 People\nFree to Choose Property\nFree Digital Soft Copy\nFree 2 Printed Photo (Promo)", 30, 50000, 'koneksi3'],
    ['Group GrayscaleBox', 'Grayscale', 'Harga Normal Rp. 105.000', "30 Minutes of Self Portrait\nMin 3 Orang\nRp. 19.000/Orang\nFree to Choose Property\nFree Digital Soft Copy\nFree 2 Printed Photo (Promo)", 30, 105000, 'koneksi4'],
    ['Group Thematic Self Potrait', 'Thematic', 'Sesi foto Thematic group', "30 Minutes of Self Portrait\n19.000 Per Orang, Min 3 People\nFree to Choose Background\nFree to Choose Property\nFree Digital Soft Copy\nFree 2 Printed Photo", 30, 57000, 'koneksi5'],
    ['Couple Thematic Self Potrait', 'Thematic', 'Harga Normal Rp. 100.000', "30 Minutes of Self Portrait\nMax 2 People\nFree to Choose Background\nFree to Choose Property\nFree Digital Soft Copy\nFree 2 Printed Photo", 30, 60000, 'koneksi6'],
    ['Promo Graduation Paket A', 'Graduation', 'Promo Spesial Kelulusan', "30 Menit Sesi Foto\nMaksimal 3 Orang\nBebas Pilih 1 Background\nMenggunakan Fotografer\nBebas Menggunakan Properti\nGratis Cetak 3 Foto (4R)\nGratis Semua File Via GDrive", 30, 150000, 'koneksi7'],
    ['Promo Graduation Paket B', 'Graduation', 'Promo Spesial Kelulusan Terlengkap', "30 Menit Sesi Foto\nMaksimal 3 Orang\nBebas Pilih 1 Background\nMenggunakan Fotografer\nBebas Menggunakan Properti\nGratis Cetak 3 Foto (4R)\nGratis Cetak Frame (12R)\nGratis Semua File Via GDrive", 30, 250000, 'koneksi8'],
    ['Graduation / Family / Maternity Package', 'Family', 'Paket Keluarga/Maternity', "30 Minutes of Photoshoot\nMax 3 People\n1 Thematic Background\nFree 2 Printed Photo\n5 Photo Editing\nPhotoshoot by Photographer\nFree To Choose Property\nFree Digital Soft Copy", 30, 250000, 'koneksi9']
];

foreach ($pakets as $p) {
    $paket_id = generatePaketId($conn);
    $stmt = $conn->prepare("INSERT INTO mst_paket (paket_id, paket_nm, kategori_tx, deskripsi_tx, fasilitas_tx, durasi_menit, normal_harga, thumbnail_foto, active_st) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1)");
    $stmt->bind_param('sssssids', $paket_id, $p[0], $p[1], $p[2], $p[3], $p[4], $p[5], $p[6]);
    $stmt->execute();
}

// 3. Nonaktifkan semua promo lama
$conn->query("UPDATE mst_promo SET active_st = 0");

// 4. Insert Promo Baru
$promos = [
    ['Promo Spesial ArtBox', 'ARTBOX50', 'Diskon setengah harga', 'persen', 50.0, 50000.0, 100000.0, '2027-12-31', 0],
    ['Potongan Graduation', 'GRAD100K', 'Potongan harga langsung', 'nominal', 100000.0, 0, 200000.0, '2027-12-31', 1]
];

foreach ($promos as $pr) {
    $promo_id = generatePromoId($conn);
    $stmt = $conn->prepare("INSERT INTO mst_promo (promo_id, promo_nm, promo_kd, deskripsi_tx, tipe_potongan, potongan_nilai, maks_potongan, min_pembelian, selesai_tgl, wajib_upload_st, active_st) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)");
    $stmt->bind_param('sssssdddsi', $promo_id, $pr[0], $pr[1], $pr[2], $pr[3], $pr[4], $pr[5], $pr[6], $pr[7], $pr[8]);
    $stmt->execute();
}

echo "Data berhasil diperbarui.";
?>
