<?php

namespace Database\Seeders;

use App\Models\Institution\Institution;
use Illuminate\Database\Seeder;

class InstitutionSeeder extends Seeder {
    /**
     * Run the database seeds.
     */
    public function run(): void {
        $institutions = Institution::factory(100)->create();

        $institutions->each(function (Institution $institution) use ($institutions) {

            $related = $institutions
                ->where('id', '!=', $institution->id)
                ->random(rand(1, 3))
                ->pluck('id')
                ->toArray();

            $institution->relatedInstitutions()->syncWithoutDetaching($related);
        });
    }
}
