<?php

namespace App\Classes\Modules\Orders\Services;


class GeneratesOrderNumber
{

    /** @var ChecksIfOrderNumberExists */
   private $checkIfOrderNumberExists;

    /**
     * GeneratesBookingMarking constructor.
     * @param ChecksIfOrderNumberExists $checkIfOrderNumberExists
     */
    public function __construct(ChecksIfOrderNumberExists $checkIfOrderNumberExists)
    {
        $this->checkIfOrderNumberExists = $checkIfOrderNumberExists;
    }


    /**
     * @return int
     */
    public function execute(): int {

        $reference = rand(100000001, 999999999);
        return !$this->checkIfOrderNumberExists->execute($reference) ? $reference : self::execute();
    }

}