<?php

namespace App\Traits;

use App\Models\ViewId;
use Illuminate\Support\Str;
trait CommonUtils
{

    public function getIdFromRefNumber($ref)
    {

        $newString = substr($ref, 3);

        $newString2 = ltrim($newString, '0');

        $id = $newString2 - 741257;

        return $id;

    }
    public function getMaskId($id)
    {
        $model = new ViewId;
        $model->actual_id = $id;
        $model->temp_uuid = self::getUUID();

        $model->save();

        return $model->temp_uuid;
    }

    public function getId($uuid)
    {
        $model = ViewId::where('temp_uuid', $uuid)->first();
        if ($model) {
            return $model->actual_id;
        }
        return null;
    }
    public function getUUID()
    {
        $uuid = Str::uuid();

        $model = ViewId::where('temp_uuid', $uuid)->first();

        if ($model) {

            self::getUUID();
        }

        return $uuid;

    }
}
