<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\AssetCategory;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * Test data only.
 *
 * @extends Factory<AssetCategory>
 */
class AssetCategoryFactory extends Factory
{
    // The return shape is inherited from Factory<AssetCategory>::definition().
    public function definition(): array
    {
        return [
            'parent_id' => null,
            'name' => fake()->randomElement([
                'Laptop', 'Desktop', 'Monitor', 'Mobile Phone', 'Keyboard',
                'Headset', 'Docking Station', 'Printer', 'Tablet', 'Router',
            ]).' '.Str::upper(Str::random(3)),
            'code' => Str::upper(Str::random(5)),
            'depreciation_years' => fake()->numberBetween(3, 5),
            'default_warranty_months' => fake()->randomElement([12, 24, 36]),
            'is_active' => true,
        ];
    }

    public function inactive(): static
    {
        return $this->state(fn (array $attributes): array => [
            'is_active' => false,
        ]);
    }

    /**
     * A subcategory of the given root.
     */
    public function childOf(AssetCategory $parent): static
    {
        return $this->state(fn (array $attributes): array => [
            'parent_id' => $parent->getKey(),
        ]);
    }
}
