<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

namespace Kufer\Web\Classes\Identifier;

use Kufer\Web\Classes\Addfunctions\Guid;

class IdentifierFactory
{
  
  public static function fromIds(array $ids): array
  {
    return array_map(function($id) {
      return new Identifier(intval($id), new Guid());
    }, $ids);
  }

  
  public static function createFromIdIfNecessary($idOrIdentifier): Identifier
  {
    if (!($idOrIdentifier instanceof Identifier)) {
      return Identifier::fromId($idOrIdentifier);
    }

    return $idOrIdentifier;
  }

  
  public static function createFromIdsIfNecessary($idsOrIdentifiers): array
  {
    return array_map(self::class . '::createFromIdIfNecessary', $idsOrIdentifiers);
  }

  public static function fromStringId(string $id, Guid $guid): Identifier
  {
    if ($id == '') {
      return Identifier::fromGuid($guid);
    }

    return new Identifier(intval($id), $guid);
  }
}