<?php

namespace Database\Factories;

use App\Enums\IsActive;
use App\Models\Department;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Department>
 */
class DepartmentFactory extends Factory
{
    protected $model = Department::class;

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $name = $this->faker->randomElement([
            'Dinas Komunikasi dan Informatika',
            'Dinas Pendidikan',
            'Dinas Kesehatan',
            'Dinas Pekerjaan Umum',
            'Dinas Sosial',
            'Dinas Pariwisata',
            'Dinas Perhubungan',
            'Dinas Lingkungan Hidup',
        ]);

        return [
            'name' => $name,
            'alias' => strtoupper(substr(str_replace(['Dinas ', ' dan ', ' '], ['', '', ''], $name), 0, 10)),
            'is_active' => $this->faker->randomElement([IsActive::ACTIVE->value, IsActive::INACTIVE->value]),
            'sort_order' => $this->faker->numberBetween(0, 100),
        ];
    }

    /**
     * Indicate that the department is active.
     */
    public function active(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_active' => IsActive::ACTIVE->value,
        ]);
    }

    /**
     * Indicate that the department is inactive.
     */
    public function inactive(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_active' => IsActive::INACTIVE->value,
        ]);
    }
}
