<?php

declare(strict_types=1);

namespace apexl\Io\modules\user\TestInfrastructure;

use apexl\Io\interfaces\GlobalDataInterface;
use apexl\Io\modules\user\entities\userEntity;
use apexl\Io\modules\user\enums\permissions\Common;
use DI\DependencyException;
use DI\NotFoundException;
use function apexl\Io\container;

trait SpoofsGlobalUser
{
    /**
     * @throws DependencyException
     * @throws NotFoundException
     */
    protected function addGlobalUser(): void
    {
        $user = userEntity::factory()->create([
            'first_name' => 'ETL',
            'last_name' => 'User',
            'email' => 'etluser@example.com',
        ]);
        $user->addPermission(Common::BYPASS);
        container()->get(GlobalDataInterface::class)->addData('entities', ['user' => ['entity' => $user]]);
    }
}
