<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Milon\Barcode\Facades\DNS1DFacade;

class BarcodeGeneratorController extends Controller
{
    /**
     * Barcode image generator
     */
    public function index(Request $request)
    {
        $request->validate([
            'barcode' => ['required'],
        ]);

        return Storage::download(
            Str::after(
                DNS1DFacade::getBarcodePNGPath(
                    code: $request->barcode,
                    type: config('barcode.default_type'),
                    showCode: true,
                ),
                'storage/app/'
            )
        );
    }
}
