<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
use Seat\Eseye\Exceptions\RequestFailedException;

use App\Models\Lookup\SolarSystem;

class SolarSystemSeeder extends Seeder
{
    /**
     * Run the database seeds.
     * 
     * @return void
     */
    public function run(): void
    {
        $esi = new Eseye();
        $systems = $esi->invoke('get', '/universe/systems/');

        foreach($systems as $system) {
            try {
                $info = $esi->invoke('get', '/universe/systems/{system_id}/', [
                    'system_id' => $system,
                ]);
            } catch(RequestFailedException $e) {
                return;
            }

            SolarSystem::updateOrCreate([
                'solar_system_id' => $system,
            ],[
                'name' => $info->name,
                'solar_system_id' => $system,
            ]);
        }
    }
}
