<?php

namespace App\Service\Utils;

use Exception;

class Uuid
{
    /**
     * Generates an UUID v4
     *
     * @param ?int $length To limit the length of the uuid (standard uuid count 36 cars). Warning: reducing
     *                   the number of characters breaks the warranty of global unity.
     * @return string
     * @throws Exception
     */
    public static function uuid(int $length = null): string
    {
        $uuid = \Ramsey\Uuid\Uuid::uuid4()->toString();
        return $length !== null ? substr($uuid, 0, $length) : $uuid;
    }
}
