<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    use WithoutModelEvents;

    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        // Create Test User
        $user = User::factory()->create([
            'name' => 'Admin User',
            'email' => 'test@example.com',
            'password' => bcrypt('password'),
        ]);

        // Create Lodgings
        $cabana1 = \App\Models\Lodging::create([
            'type' => 'cabana', 'number' => 1, 'description' => 'Cabaña Familiar con vista al río',
            'price_adult' => 250, 'price_kid_10_15' => 150, 'price_kid_5_10' => 100, 'is_active' => true
        ]);
        $cabana2 = \App\Models\Lodging::create([
            'type' => 'cabana', 'number' => 2, 'description' => 'Cabaña Pequeña',
            'price_adult' => 200, 'price_kid_10_15' => 120, 'price_kid_5_10' => 80, 'is_active' => true
        ]);
        $domo1 = \App\Models\Lodging::create([
            'type' => 'domo', 'number' => 1, 'description' => 'Domo Parejas VIP',
            'price_adult' => 300, 'price_kid_10_15' => 0, 'price_kid_5_10' => 0, 'is_active' => true
        ]);

        // Create Catalog Services
        \App\Models\CatalogService::create(['name' => 'Decoración Romántica', 'description' => 'Pétalos, vino y velas', 'price' => 150, 'is_active' => true]);
        \App\Models\CatalogService::create(['name' => 'Pastel de Cumpleaños', 'description' => 'Pastel de chocolate (8 porciones)', 'price' => 120, 'is_active' => true]);
        \App\Models\CatalogService::create(['name' => 'Leña extra', 'description' => 'Carga de leña para chimenea', 'price' => 30, 'is_active' => true]);

        $today = date('Y-m-d');
        $tomorrow = date('Y-m-d', strtotime('+1 day'));
        $yesterday = date('Y-m-d', strtotime('-1 day'));

        // Create Reservations
        \App\Models\Reservation::create([
            'customer_name' => 'Juan Pérez', 'phone' => '78945612', 'lodging_id' => $cabana1->id,
            'adults' => 2, 'kids_10_15' => 1, 'kids_5_10' => 0,
            'total_cost' => 650, 'advance_payment' => 300, 'balance' => 350,
            'payment_method' => 'qr', 'reservation_date' => $yesterday,
            'check_in' => $today, 'check_out' => $tomorrow,
            'status' => 'confirmado', 'user_id' => $user->id,
        ]);

        \App\Models\Reservation::create([
            'customer_name' => 'Maria Gomez', 'phone' => '71122334', 'lodging_id' => $domo1->id,
            'adults' => 2, 'kids_10_15' => 0, 'kids_5_10' => 0, 'package_type' => 'Aniversario',
            'total_cost' => 750, 'advance_payment' => 750, 'balance' => 0,
            'payment_method' => 'efectivo', 'reservation_date' => $today,
            'check_in' => $tomorrow, 'check_out' => date('Y-m-d', strtotime('+3 days')),
            'status' => 'confirmado', 'user_id' => $user->id,
        ]);

        \App\Models\Reservation::create([
            'customer_name' => 'Carlos López', 'phone' => '79988776', 'lodging_id' => $cabana2->id,
            'adults' => 3, 'kids_10_15' => 0, 'kids_5_10' => 2,
            'total_cost' => 760, 'advance_payment' => 200, 'balance' => 560,
            'payment_method' => 'qr', 'reservation_date' => date('Y-m-d', strtotime('-5 days')),
            'check_in' => date('Y-m-d', strtotime('-2 days')), 'check_out' => $today,
            'status' => 'confirmado', 'user_id' => $user->id,
        ]);

        \App\Models\Reservation::create([
            'customer_name' => 'Ana Martínez', 'phone' => '65544332', 'lodging_id' => $cabana1->id,
            'adults' => 2, 'kids_10_15' => 0, 'kids_5_10' => 0,
            'total_cost' => 500, 'advance_payment' => 100, 'balance' => 400,
            'payment_method' => 'qr', 'reservation_date' => $today,
            'check_in' => date('Y-m-d', strtotime('+5 days')), 'check_out' => date('Y-m-d', strtotime('+7 days')),
            'status' => 'cancelado', 'user_id' => $user->id,
        ]);
    }
}
