<?php

namespace Database\Seeders;

use App\Models\City;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\File;

class CitySeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $jsonData = File::get(base_path('database/seeders/data/secteurs.json'));
        $data = json_decode($jsonData, true);

        $this->command->getOutput()->progressStart(count($data));
        // Loop through the data and insert it into the cities table
        foreach ($data as $row) {
            // Insert into the secteurs table
            City::firstOrCreate([
                'name' => $row['VILLE'],
            ]);

            $this->command->getOutput()->progressAdvance();
        }
        $this->command->getOutput()->progressFinish();
    }
}
