<?php

namespace Database\Seeders;

use App\Models\Setting;
use Illuminate\Database\Seeder;

class SettingSeeder extends Seeder
{
    public function run(): void
    {
        $settings = [

            // ── Toko ─────────────────────────────────────────────────────
            [
                'key'   => 'store_name',
                'value' => 'Titipin Ba Be',
                'group' => 'store',
            ],
            [
                'key'   => 'store_logo',
                'value' => null,
                'group' => 'store',
            ],
            [
                'key'   => 'operating_hours',
                'value' => '07.00 – 21.00 WIB',
                'group' => 'store',
            ],
            [
                'key'   => 'min_order',
                'value' => '20000', // dalam Rupiah, string agar fleksibel
                'group' => 'store',
            ],
            [
                'key'   => 'default_delivery_cost',
                'value' => '5000',
                'group' => 'store',
            ],
            [
                'key'   => 'shipping_mode',
                'value' => 'flat',
                'group' => 'store',
            ],

            // ── Identitas Toko tambahan (untuk Modul Pengaturan) ───────────
            [
                'key'   => 'store_email',
                'value' => null,
                'group' => 'contact',
            ],
            [
                'key'   => 'store_address',
                'value' => null,
                'group' => 'contact',
            ],

            // ── Pesanan (untuk Modul Pengaturan) ───────────────────────────
            [
                'key'   => 'auto_cancel_pending_minutes',
                'value' => '60', // pesanan pending otomatis dibatalkan setelah 60 menit
                'group' => 'order',
            ],
            [
                'key'   => 'checkout_duration_minutes',
                'value' => '15', // batas waktu customer menyelesaikan checkout
                'group' => 'order',
            ],

            // ── Notifikasi (untuk Modul Pengaturan) ────────────────────────
            [
                'key'   => 'wa_notification_enabled',
                'value' => '1', // '1' = aktif, '0' = nonaktif
                'group' => 'notification',
            ],

            // ── Kontak ───────────────────────────────────────────────────
            [
                'key'   => 'wa_admin',
                'value' => null, // diisi Owner di halaman Setting
                'group' => 'contact',
            ],

            // ── Pembayaran ───────────────────────────────────────────────
            [
                'key'   => 'qris_image',
                'value' => null,
                'group' => 'payment',
            ],
            [
                'key'   => 'bank_accounts',
                // JSON array rekening. Bisa lebih dari satu bank.
                'value' => json_encode([
                    [
                        'bank_name'      => 'BCA',
                        'account_number' => '',
                        'account_name'   => '',
                    ],
                ]),
                'group' => 'payment',
            ],
            [
                'key'   => 'payment_deadline_hours',
                'value' => '24', // jam batas waktu pembayaran transfer/QRIS
                'group' => 'payment',
            ],
        ];

        foreach ($settings as $setting) {
            Setting::updateOrCreate(
                ['key' => $setting['key']],
                [
                    'value' => $setting['value'],
                    'group' => $setting['group'],
                ]
            );
        }

        $this->command->info('✓ Setting default berhasil dibuat (' . count($settings) . ' keys).');
    }
}
