<?php

namespace Database\Seeders;

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

class PostalCodeSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
// Get JSON data from the file
        $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
            PostalCode::firstOrCreate([
                'code' => $row['NOUVEAU CODE POSTAL'],
            ],[
                'name' => $row['QUARTIER'] . ' - ' . $row['VILLE'],
                'description' => $row['QUARTIER'] . ' - ' . $row['VILLE'],
            ]);

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