<?php

namespace Database\Factories;

use App\Models\Municipality;
use App\Models\Neighborhood;
use App\Models\Province;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * @extends Factory<Municipality>
 */
class MunicipalityFactory extends Factory
{
    protected $model = Municipality::class;

    public function definition(): array
    {
        $name = fake()->unique()->city();

        return [
            'province_id' => Province::factory(),
            'name' => $name,
            'code' => Str::upper(Str::slug($name, '_')),
        ];
    }

    public function withNeighborhoods(int $count = 3): static
    {
        return $this->afterCreating(function (Municipality $municipality) use ($count) {
            Neighborhood::factory()
                ->count($count)
                ->for($municipality)
                ->create();
        });
    }
}
