<?php

namespace Sideso\QzLaravel\Http\Controllers;

use Sideso\QzLaravel\QzLaravel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage;

class QzController extends Controller
{
    public function sign(Request $request)
    {
        $request->validate([
            'dataToSign' => 'required',
        ]);

        $signature = QzLaravel::sign($request->dataToSign);

        return response($signature, 200)
			->header('Content-Type', 'text/plain');
    }

    public function certificate()
    {
        return response(QzLaravel::publicCertificate(), 200)
            ->header('Content-Type', 'text/plain');
    }

    public function installer()
    {
        $installer = Storage::disk('public')->get('qz-laravel/qz-installer.exe');

        return response($installer, 200)
            ->header('Content-Type', 'application/vnd.microsoft.portable-executable')
            ->header('Content-Disposition', 'attachment; filename="qz-installer.exe"');
    }
}