<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class DatabaseSeeder extends Seeder
{
    // php artisan db:seed --class=DatabaseSeeder
    // php artisan db:seed
    /**
     * Seed the application's database.
     */
    public function run(): void
    {

        DB::statement('SET FOREIGN_KEY_CHECKS=0;');
        // 1️⃣ Clear previous data
        DB::table('meal_packages')->truncate();
        // DB::table('addons')->truncate();
        DB::table('facilities')->truncate();
        DB::table('rooms')->truncate();
        DB::table('room_categories')->truncate();

        $this->call([
            UserSeeder::class,
        ]);

        DB::statement('SET FOREIGN_KEY_CHECKS=1;');

        /*
        |-----------------------------------------------------------------------
        | Facilities
        |-----------------------------------------------------------------------
        */
        DB::table('facilities')->insert([
            ['name' => 'Free WiFi', 'icon_value' => 'Wifi', 'is_icon' => true, 'scope' => 'all_rooms', 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Air Conditioning', 'icon_value' => 'SnowFlake', 'is_icon' => true, 'scope' => 'room', 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Swimming Pool', 'icon_value' => 'Pool', 'is_icon' => true, 'scope' => 'all_rooms', 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Private Balcony', 'icon_value' => 'Building', 'is_icon' => true, 'scope' => 'room_category', 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Mini Bar', 'icon_value' => 'Fridge', 'is_icon' => true, 'scope' => 'room', 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Room Service', 'icon_value' => 'Bell', 'is_icon' => true, 'scope' => 'room_category', 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
        ]);

        /*
        |-----------------------------------------------------------------------
        | Add-ons
        |-----------------------------------------------------------------------
        */
        // DB::table('addons')->insert([
        //     [
        //         'title' => 'Airport Pickup',
        //         'description' => 'Private airport pickup service from airport to hotel.',
        //         'price' => 25000,
        //         'unit' => 1,
        //         'min_quantity' => 0,
        //         'max_quantity' => 1,
        //         'calculation_type' => 'per_booking',
        //         'is_published' => true,
        //         'default_availability' => false,
        //         'is_variant' => true,
        //         'scope' => 'booking',
        //         'apply_on' => 'check_in',
        //         'icon_value' => 'Truck',            // Lucide icon
        //         'is_icon' => true,
        //         'tag' => 'Transport',
        //         'created_at' => now(),
        //         'updated_at' => now()
        //     ],
        //     [
        //         'title' => 'Extra Bed',
        //         'description' => 'Additional bed setup in the room.',
        //         'price' => 2000,
        //         'unit' => 1,
        //         'min_quantity' => 0,
        //         'max_quantity' => 1,
        //         'calculation_type' => 'per_room_per_night',
        //         'is_published' => true,
        //         'default_availability' => false,
        //         'is_variant' => false,
        //         'scope' => 'room',
        //         'apply_on' => 'entire_stay',
        //         'icon_value' => 'Bed',              // Lucide icon
        //         'is_icon' => true,
        //         'tag' => 'Comfort',
        //         'created_at' => now(),
        //         'updated_at' => now()
        //     ],
        //     [
        //         'title' => 'Breakfast',
        //         'description' => 'Daily breakfast during your stay.',
        //         'price' => 1000,
        //         'unit' => 1,
        //         'min_quantity' => 0,
        //         'max_quantity' => null,
        //         'calculation_type' => 'per_person_per_night',
        //         'is_published' => true,
        //         'default_availability' => true,
        //         'is_variant' => false,
        //         'scope' => 'all_rooms',
        //         'apply_on' => 'entire_stay',
        //         'icon_value' => 'Coffee',           // Lucide icon
        //         'is_icon' => true,
        //         'tag' => 'Food',
        //         'created_at' => now(),
        //         'updated_at' => now()
        //     ],
        //     [
        //         'title' => 'Spa Access',
        //         'description' => 'Access to spa and wellness facilities.',
        //         'price' => 5000,
        //         'unit' => 1,
        //         'min_quantity' => 1,
        //         'max_quantity' => 5,
        //         'calculation_type' => 'per_person',
        //         'is_published' => true,
        //         'default_availability' => false,
        //         'is_variant' => false,
        //         'scope' => 'booking',
        //         'apply_on' => 'dont_apply',
        //         'icon_value' => 'Sparkles',        // Lucide icon
        //         'is_icon' => true,
        //         'tag' => 'Relax',
        //         'created_at' => now(),
        //         'updated_at' => now()
        //     ],
        //     [
        //         'title' => 'Late Checkout',
        //         'description' => 'Extend your checkout time until 2 PM.',
        //         'price' => 1550,
        //         'unit' => 1,
        //         'min_quantity' => 0,
        //         'max_quantity' => 1,
        //         'calculation_type' => 'per_room',
        //         'is_published' => true,
        //         'default_availability' => false,
        //         'is_variant' => false,
        //         'scope' => 'room',
        //         'apply_on' => 'check_out',
        //         'icon_value' => 'Clock',            // Lucide icon
        //         'is_icon' => true,
        //         'tag' => 'Convenience',
        //         'created_at' => now(),
        //         'updated_at' => now()
        //     ],
        //     [
        //         'title' => 'Romantic Decoration',
        //         'description' => 'Room decorated with flowers and candles.',
        //         'price' => 4000,
        //         'unit' => 1,
        //         'min_quantity' => 0,
        //         'max_quantity' => 1,
        //         'calculation_type' => 'per_room',
        //         'is_published' => true,
        //         'default_availability' => false,
        //         'is_variant' => false,
        //         'scope' => 'room',
        //         'apply_on' => 'check_in',
        //         'icon_value' => 'Heart',            // Lucide icon
        //         'is_icon' => true,
        //         'tag' => 'Special',
        //         'created_at' => now(),
        //         'updated_at' => now()
        //     ],
        // ]);

        /*
        |-----------------------------------------------------------------------
        | Meal Packages (only 3)
        |-----------------------------------------------------------------------
        */
        DB::table('meal_packages')->insert([
            [
                'title' => 'Breakfast Only',
                'description' => 'Daily breakfast included',
                'price' => 1500,
                'scope' => 'room_category',
                'tag' => 'Popular',
                'icon_value' => 'Coffee',
                'is_icon' => true,
                'is_published' => true,
                'default_availability' => true,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'title' => 'Half Board',
                'description' => 'Breakfast and dinner included',
                'price' => 2500,
                'scope' => 'room',
                'tag' => 'Best Value',
                'icon_value' => 'Utensils',
                'is_icon' => true,
                'is_published' => true,
                'default_availability' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'title' => 'Full Board',
                'description' => 'Breakfast, lunch and dinner included',
                'price' => 4000,
                'scope' => 'room_category',
                'tag' => 'Premium',
                'icon_value' => 'Plate',
                'is_icon' => true,
                'is_published' => true,
                'default_availability' => false,
                'created_at' => now(),
                'updated_at' => now()
            ],
        ]);

        /*
        |-----------------------------------------------------------------------
        | Room Categories
        |-----------------------------------------------------------------------
        */
        $categories = [
            ['short_name' => 'Standard Rooms', 'name' => 'Standard Rooms', 'slug' => 'standard-rooms', 'sort_order' => 1, 'description' => 'Comfortable rooms for budget travelers.', 'base_price' => 10000, 'default_capacity' => 2, 'default_bed_count' => 1, 'default_bathroom_count' => 1, 'default_size' => 20, 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
            ['short_name' => 'Deluxe Rooms', 'name' => 'Deluxe Rooms', 'slug' => 'deluxe-rooms', 'sort_order' => 2, 'description' => 'Spacious rooms with premium amenities.', 'base_price' => 15000, 'default_capacity' => 3, 'default_bed_count' => 2, 'default_bathroom_count' => 1, 'default_size' => 35, 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
            ['short_name' => 'Luxury Rooms', 'name' => 'Luxury Rooms', 'slug' => 'luxury-rooms', 'sort_order' => 3, 'description' => 'Luxurious suites with separate living area.', 'base_price' => 20000, 'default_capacity' => 4, 'default_bed_count' => 2, 'default_bathroom_count' => 2, 'default_size' => 50, 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
        ];

        $categoryIds = [];
        foreach ($categories as $category) {
            $id = DB::table('room_categories')->insertGetId($category);
            $categoryIds[] = $id;
        }

        /*
        |-----------------------------------------------------------------------
        | Rooms (5)
        |-----------------------------------------------------------------------
        */
        $rooms = [
            ['room_category_id' => $categoryIds[0], 'room_number' => '101', 'floor' => '1', 'price_override' => null, 'view' => 'Garden View', 'description' => 'Near the lobby, comfortable for 2 guests.', 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
            ['room_category_id' => $categoryIds[0], 'room_number' => '102', 'floor' => '1', 'price_override' => 12000, 'view' => null, 'description' => null, 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
            ['room_category_id' => $categoryIds[1], 'room_number' => '201', 'floor' => '2', 'price_override' => 11000, 'view' => 'Sea View', 'description' => 'Spacious room with balcony and premium bed.', 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
            ['room_category_id' => $categoryIds[1], 'room_number' => '202', 'floor' => '2', 'price_override' => null, 'view' => null, 'description' => null, 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
            ['room_category_id' => $categoryIds[2], 'room_number' => '301', 'floor' => '3', 'price_override' => 22000, 'view' => 'Ocean View', 'description' => 'Luxury suite with living room and private balcony.', 'is_published' => true, 'created_at' => now(), 'updated_at' => now()],
        ];

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