<?php

namespace App\Services;

use App\Models\Link;
use Illuminate\Support\Str;

class ShortCodeGenerator
{
    public function generate(int $length = 7): string
    {
        do {
            $code = Str::lower(Str::random($length));
        } while (Link::query()->where('short_code', $code)->exists());

        return $code;
    }
}
