<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\TripRequest;
use App\Models\User;
use Carbon\Carbon;

class TripRequestSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // إنشاء طلبات رحلات تجريبية
        $passengers = User::where('user_type', 'passenger')->get();
        
        if ($passengers->isEmpty()) {
            $this->command->info('لا يوجد ركاب، تم تخطي إنشاء طلبات الرحلات');
            return;
        }

        $tripRequests = [
            [
                'passenger_id' => $passengers->first()->id,
                'pickup_location' => 'Nassiriya General Hospital',
                'pickup_lat' => 31.9550,
                'pickup_lng' => 46.2580,
                'destination_location' => 'Central Market',
                'destination_lat' => 31.9520,
                'destination_lng' => 46.2560,
                'distance' => 2.5,
                'duration' => 8,
                'proposed_price' => 5000,
                'notes' => 'أحتاج سيارة للوصول إلى السوق',
                'status' => 'pending',
                'expires_at' => Carbon::now()->addHours(1),
                'driver_id' => null,
                'accepted_at' => null,
                'rejected_at' => null,
                'rejection_reason' => null,
            ],
            [
                'passenger_id' => $passengers->first()->id,
                'pickup_location' => 'Nassiriya University',
                'pickup_lat' => 31.0500,
                'pickup_lng' => 46.2600,
                'destination_location' => 'Gas Station Al-Rashid',
                'destination_lat' => 31.9500,
                'destination_lng' => 46.2550,
                'distance' => 3.2,
                'duration' => 10,
                'proposed_price' => 6000,
                'notes' => 'من الجامعة إلى محطة البنزين',
                'status' => 'pending',
                'expires_at' => Carbon::now()->addHours(1),
                'driver_id' => null,
                'accepted_at' => null,
                'rejected_at' => null,
                'rejection_reason' => null,
            ],
            [
                'passenger_id' => $passengers->first()->id,
                'pickup_location' => 'Restaurant Al-Najaf',
                'pickup_lat' => 31.9540,
                'pickup_lng' => 46.2570,
                'destination_location' => 'Taxi Station',
                'destination_lat' => 31.9530,
                'destination_lng' => 46.2585,
                'distance' => 1.8,
                'duration' => 6,
                'proposed_price' => 4000,
                'notes' => 'من المطعم إلى محطة التاكسي',
                'status' => 'pending',
                'expires_at' => Carbon::now()->addHours(1),
                'driver_id' => null,
                'accepted_at' => null,
                'rejected_at' => null,
                'rejection_reason' => null,
            ],
        ];

        foreach ($tripRequests as $requestData) {
            TripRequest::create($requestData);
            $this->command->info('تم إنشاء طلب رحلة: ' . $requestData['pickup_location'] . ' إلى ' . $requestData['destination_location']);
        }

        $this->command->info('تم إنشاء ' . count($tripRequests) . ' طلب رحلة بنجاح!');
    }
}
