<?php

namespace App\Services;

use App\DischargeTask;
use App\Filters\DischargeTaskFilters;
use App\Traits\ServiceAppAop;
use App\Facilitator;
use Endroid\QrCode\QrCode;

class FacilitatorService
{
    use ServiceAppAop;

    protected $modelClass = Facilitator::class;


    public function getQrCodeUrl(array $param): string
    {
        $facilitator_id = md5($param['facilitator_id']);
        $urlString = '/personnel/discharge/facilitator/external/' . $facilitator_id . '/index';
        $url = url($urlString);
        $url .= '?created_range=' . ($param['range'] ?? '');

        $qrCode = new QrCode($url);
        $fileURL = base_path('public/images/QRCodeIMG/facilitator_id_' . $facilitator_id . '.png');

        if (!file_exists($fileURL)) {
            $qrCode->writeFile($fileURL);
        }

        return url('images/QRCodeIMG/facilitator_id_' . $facilitator_id . '.png');
    }

}
