<?php

declare(strict_types=1);

namespace apexl\Io\modules\user\Commands;

use apexl\Io\exceptions\RecordNotFoundException;
use apexl\Io\modules\user\entities\userEntity;
use app\vendor\apexl\io\src\Io\modules\system\commands\DaedalusCommand;

abstract class AbstractUserCommand extends DaedalusCommand
{
    /**
     * @throws RecordNotFoundException
     */
    protected function getUser(string $idOrEmail): userEntity
    {
        $user = new userEntity();

        if (is_numeric($idOrEmail)) {
            $user->load($idOrEmail);
            if ($user->id === null) {
                throw new RecordNotFoundException();
            }

            return $user;
        }

        $user->loadBy('email', $idOrEmail);

        return $user;
    }
}
