<?php

namespace App\Classes\Modules\PackingLists\Services;


class GeneratesPackingListReferenceNumber
{

    /** @var ChecksIfPackingListReferenceNumberExists */
    private $checksIfPackingListReferenceNumberExists;

    /**
     * GeneratesTransactionBillNo constructor.
     * @param ChecksIfPackingListReferenceNumberExists $checksIfPackingListRefrenceNumberExists
     */
    public function __construct(ChecksIfPackingListReferenceNumberExists $checksIfPackingListReferenceNumberExists)
    {
        $this->checksIfPackingListReferenceNumberExists = $checksIfPackingListReferenceNumberExists;
    }

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

        $referenceNumber = mt_rand(10000000, 99999999);

        return !$this->checksIfPackingListReferenceNumberExists->execute($referenceNumber) ? $referenceNumber : self::execute();
    }
}