<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use Illuminate\Support\Facades\Schema; // Tambahkan ini di atas

class TransaksiSeeder extends Seeder
{
    public function run(): void
    {
        // 1. Matikan pengecekan Foreign Key sementara (Supaya bisa hapus data sembarangan)
        Schema::disableForeignKeyConstraints();

        // 2. Kosongkan tabel sebelum diisi ulang (Urutan gak masalah karena FK dimatikan)
        DB::table('detail_additionals')->truncate();
        DB::table('booking_fotos')->truncate();
        DB::table('transaksi_bukets')->truncate();

        // 3. Nyalakan lagi pengecekan Foreign Key
        Schema::enableForeignKeyConstraints();
        $buketData = [
            [
                'no_invoice'        => 'INV-BKT-' . time() . '01',
                'id_pelanggan'      => 1, // Pastikan ID ini ada di tabel pelanggans
                'id_buket'          => 1, // Buket Mawar (Harga: 150000)
                'request'           => 'tema navy',
                'ucapan'           => '"Happy Graduation Sayang"',
                'tgl_ambil'         => Carbon::now()->addDays(2)->format('Y-m-d H:i:s'),
                'total_bayar'       => 150000,
                'bukti_bayar'       => 'img/payment/buket/bukti1.jpg',
                'status_transaksi'  => 'selesai',
                'created_at'        => now(),
                'updated_at'        => now(),
            ],
            [
                'no_invoice'        => 'INV-BKT-' . time() . '02',
                'id_pelanggan'      => 2,
                'id_buket'          => 2, // Snack Bouquet (Harga: 75000)
                'request'           => 'Snacknya jangan yang pedas',
                'ucapan'           => 'semangat bub',
                'tgl_ambil'         => Carbon::now()->subDays(1)->format('Y-m-d H:i:s'), // Sudah lewat
                'total_bayar'       => 75000,
                'bukti_bayar'       => 'img/payment/buket/bukti2.jpg',
                'status_transaksi'  => 'diterima',
                'created_at'        => now()->subDays(2),
                'updated_at'        => now()->subDays(1),
            ],
            [
                'no_invoice'        => 'INV-BKT-' . time() . '03',
                'id_pelanggan'      => 2,
                'id_buket'          => 1, // Snack Bouquet (Harga: 75000)
                'request'           => 'Snacknya jangan yang pedas',
                'ucapan'           => 'semangat bub',
                'tgl_ambil'         => Carbon::now()->subDays(1)->format('Y-m-d H:i:s'), // Sudah lewat
                'total_bayar'       => 75000,
                'bukti_bayar'       => 'img/payment/buket/bukti2.jpg',
                'status_transaksi'  => 'ditolak',
                'created_at'        => now()->subDays(2),
                'updated_at'        => now()->subDays(1),
            ],
            [
                'no_invoice'        => 'INV-BKT-' . time() . '04',
                'id_pelanggan'      => 2,
                'id_buket'          => 3, // Snack Bouquet (Harga: 75000)
                'request'           => 'Snacknya jangan yang pedas',
                'ucapan'           => 'semangat bub',
                'tgl_ambil'         => Carbon::now()->subDays(1)->format('Y-m-d H:i:s'), // Sudah lewat
                'total_bayar'       => 75000,
                'bukti_bayar'       => 'img/payment/buket/bukti2.jpg',
                'status_transaksi'  => 'menunggu_verifikasi',
                'created_at'        => now()->subDays(2),
                'updated_at'        => now()->subDays(1),
            ],
            [
                'no_invoice'        => 'INV-BKT-' . time() . '05',
                'id_pelanggan'      => 1,
                'id_buket'          => 3, // Snack Bouquet (Harga: 75000)
                'request'           => 'Snacknya jangan yang pedas',
                'ucapan'           => 'semangat bub',
                'tgl_ambil'         => Carbon::now()->subDays(1)->format('Y-m-d H:i:s'), // Sudah lewat
                'total_bayar'       => 75000,
                'bukti_bayar'       => 'img/payment/buket/bukti2.jpg',
                'status_transaksi'  => 'menunggu_verifikasi',
                'created_at'        => now()->subDays(2),
                'updated_at'        => now()->subDays(1),
            ]
        ];

        DB::table('transaksi_bukets')->insert($buketData);


        // --- 2. SEEDER BOOKING FOTO ---
        $fotoData = [
            [
                'id_booking'      => 1, // Kita set manual ID biar gampang relasi ke additional
                'no_invoice'      => 'INV-FOTO-' . time() . '01',
                'id_pelanggan'    => 1,
                'id_paket'        => 1, // Wisuda Basic (Harga: 250000)
                'tgl_booking'     => Carbon::now()->addDays(5)->format('Y-m-d'),
                'jam_mulai'       => '09:00:00',
                'jam_selesai'     => '10:00:00', // Durasi 60 menit sesuai paket
                'total_bayar'     => 250000 + 10000, // Harga Paket + Additional (Bando)
                'bukti_bayar'       => 'img/payment/foto/bukti1.jpg',
                'status_booking'  => 'diterima',
                'created_at'      => now(),
                'updated_at'      => now(),
            ],
            [
                'id_booking'      => 2,
                'no_invoice'      => 'INV-FOTO-' . time() . '02',
                'id_pelanggan'    => 2,
                'id_paket'        => 2, // Couple Studio (Harga: 350000)
                'tgl_booking'     => Carbon::now()->addDays(1)->format('Y-m-d'),
                'jam_mulai'       => '13:00:00',
                'jam_selesai'     => '13:45:00', // Durasi 45 menit
                'total_bayar'     => 350000 + (35000 * 2), // Paket + (Kostum * 2)
                'bukti_bayar'       => 'img/payment/foto/bukti1.jpg',
                'status_booking'  => 'ditolak',
                'created_at'      => now(),
                'updated_at'      => now(),
            ],
            [
                'id_booking'      => 3,
                'no_invoice'      => 'INV-FOTO-' . time() . '03',
                'id_pelanggan'    => 1,
                'id_paket'        => 2, // Couple Studio (Harga: 350000)
                'tgl_booking'     => Carbon::now()->addDays(1)->format('Y-m-d'),
                'jam_mulai'       => '13:00:00',
                'jam_selesai'     => '13:45:00', // Durasi 45 menit
                'total_bayar'     => 350000 + (35000 * 2), // Paket + (Kostum * 2)
                'bukti_bayar'       => 'img/payment/foto/bukti1.jpg',
                'status_booking'  => 'menunggu_verifikasi',
                'created_at'      => now(),
                'updated_at'      => now(),
            ],
            [
                'id_booking'      => 4,
                'no_invoice'      => 'INV-FOTO-' . time() . '04',
                'id_pelanggan'    => 2,
                'id_paket'        => 2, // Couple Studio (Harga: 350000)
                'tgl_booking'     => Carbon::now()->addDays(1)->format('Y-m-d'),
                'jam_mulai'       => '13:00:00',
                'jam_selesai'     => '13:45:00', // Durasi 45 menit
                'total_bayar'     => 350000 + (35000 * 2), // Paket + (Kostum * 2)
                'bukti_bayar'       => 'img/payment/foto/bukti1.jpg',
                'status_booking'  => 'menunggu_verifikasi',
                'created_at'      => now(),
                'updated_at'      => now(),
            ],
            [
                'id_booking'      => 5,
                'no_invoice'      => 'INV-FOTO-' . time() . '05',
                'id_pelanggan'    => 1,
                'id_paket'        => 2, // Couple Studio (Harga: 350000)
                'tgl_booking'     => Carbon::now()->addDays(1)->format('Y-m-d'),
                'jam_mulai'       => '13:00:00',
                'jam_selesai'     => '13:45:00', // Durasi 45 menit
                'total_bayar'     => 350000 + (35000 * 2), // Paket + (Kostum * 2)
                'bukti_bayar'       => 'img/payment/foto/bukti1.jpg',
                'status_booking'  => 'selesai',
                'created_at'      => now(),
                'updated_at'      => now(),
            ]
        ];

        DB::table('booking_fotos')->insert($fotoData);


        // --- 3. SEEDER DETAIL ADDITIONAL (Relasi ke Booking Foto) ---
        $additionalData = [
            // SKENARIO 1: Booking ID 1 (Satu Item Additional)
            [
                'id_booking'    => 4,
                'id_additional' => 3, // Bando Kucing
                'qty'           => 1,
                'subtotal'      => 10000,
                'created_at'    => now(),
                'updated_at'    => now(),
            ],
            [
                'id_booking'    => 4,
                'id_additional' => 2, // Bando Kucing
                'qty'           => 1,
                'subtotal'      => 10000,
                'created_at'    => now(),
                'updated_at'    => now(),
            ],

            // SKENARIO 2: Booking ID 3 (Dua Item Additional Berbeda)
            // Item Pertama
            [
                'id_booking'    => 3,
                'id_additional' => 2, // Kostum Boneka
                'qty'           => 1,
                'subtotal'      => 35000,
                'created_at'    => now(),
                'updated_at'    => now(),
            ],
            // Item Kedua
            [
                'id_booking'    => 3,
                'id_additional' => 3, // Bando Kucing
                'qty'           => 2,
                'subtotal'      => 20000, // 2 x 10000
                'created_at'    => now(),
                'updated_at'    => now(),
            ],
        ];

        DB::table('detail_additionals')->insert($additionalData);
    }
}
