<?php

namespace Database\Seeders;

use App\Models\Building;
use App\Models\Unit;
use Illuminate\Database\Seeder;

class BuildingAndUnitsSeeder extends Seeder
{
    public function run(): void
    {
        $building = Building::query()->firstOrCreate(
            ['name' => config('sharjino.building_name', 'Hekmat Complex')],
            [
                'default_unit_count' => config('sharjino.default_unit_count', 44),
                'start_jalali_year' => config('sharjino.start_jalali_year', 1404),
            ]
        );

        for ($i = 1; $i <= (int) $building->default_unit_count; $i++) {
            Unit::query()->firstOrCreate([
                'building_id' => $building->id,
                'unit_number' => (string) $i,
            ]);
        }
    }
}
