<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Agent;
use App\Models\Warehouse;

class AgentSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $warehouses = Warehouse::all();
        
        // Agent names for Pakistani context
        $agentNames = [
            ['Ahmed', 'Ali', 'Hassan'],
            ['Usman', 'Zain', 'Bilal'],
            ['Faisal', 'Kamran', 'Tariq'],
            ['Saeed', 'Nadeem', 'Rashid'],
            ['Waseem', 'Shahid', 'Imran'],
        ];

        $index = 0;
        foreach ($warehouses as $warehouse) {
            $names = $agentNames[$index % count($agentNames)];
            
            for ($i = 0; $i < 3; $i++) {
                Agent::updateOrCreate(
                    [
                        'name' => $names[$i],
                        'warehouse_id' => $warehouse->id,
                    ],
                    [
                        'email' => strtolower($names[$i]) . '@' . strtolower(str_replace(' ', '', $warehouse->name)) . '.com',
                        'phone' => '030' . rand(10000000, 99999999),
                        'warehouse_id' => $warehouse->id,
                    ]
                );
            }
            
            $index++;
        }
    }
}
