<?php

namespace Database\Factories;

use App\Models\BaselineSnapshot;
use App\Models\BaselineSnapshotItem;
use App\Support\Baselines\BaselineSubjectKey;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<BaselineSnapshotItem>
 */
class BaselineSnapshotItemFactory extends Factory
{
    protected $model = BaselineSnapshotItem::class;

    /**
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $displayName = fake()->words(3, true);
        $policyType = 'deviceConfiguration';

        $subjectKey = BaselineSubjectKey::fromDisplayName($displayName);
        $subjectExternalId = $subjectKey !== null
            ? BaselineSubjectKey::workspaceSafeSubjectExternalId($policyType, $subjectKey)
            : fake()->uuid();

        return [
            'baseline_snapshot_id' => BaselineSnapshot::factory(),
            'subject_type' => 'policy',
            'subject_external_id' => $subjectExternalId,
            'subject_key' => $subjectKey,
            'policy_type' => $policyType,
            'baseline_hash' => hash('sha256', fake()->uuid()),
            'meta_jsonb' => ['display_name' => $displayName],
        ];
    }
}
