<?php

namespace App\Services;

use Illuminate\Support\ServiceProvider;
use App\Exceptions\InvalidUuidException;

class UuidService extends ServiceProvider {
    public function isValid(string $uuid) {
        $regex = '/^[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}$/i';
        return preg_match($regex, $uuid) === 1;
    }

    public function validOrFail(string $uuid) {
        if(!$this->isValid($uuid)) {
            throw new InvalidUuidException($uuid);
        }
    }
}
