<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\ApiKey;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

/**
 * @extends Factory<ApiKey>
 */
class ApiKeyFactory extends Factory
{
    protected $model = ApiKey::class;

    public function definition(): array
    {
        return [
            'tenant_id' => Tenant::factory(),
            'user_id' => User::factory(),
            'name' => 'API-ключ',
            'key_hash' => Hash::make(Str::random(48)),
            'key_prefix' => 'lpkapi_'.Str::lower(Str::random(3)),
            'scopes' => ['read'],
            'last_used_at' => null,
            'expires_at' => now()->addYear(),
            'is_active' => true,
            'created_at' => now(),
        ];
    }
}
