<?php

namespace App\Classes\Modules\Exports\ControllersLogic;


use App\Classes\General\Abstracts\Abstract2ControllerLogic;
use App\Classes\Modules\Exports\Services\ExportsFeedback;
use App\Classes\Modules\Exports\Standards\Rules\CanExportFeedback;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Maatwebsite\Excel\Excel;

class ExportFeedbackDataLogic extends Abstract2ControllerLogic
{
    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Retrieved Feedback',
            'message' => 'You have successfully exported feedback data'
        ];
    }

    /** @var ExportsFeedback */
    private $exportsFeedback;

    /** @var CanExportFeedback */
    private $canExportFeedback;

    /**
     * ExportFeedbackDataLogic constructor.
     * @param ExportsFeedback $exportsFeedback
     * @param CanExportFeedback $canExportFeedback
     */
    public function __construct(ExportsFeedback $exportsFeedback, CanExportFeedback $canExportFeedback)
    {
        $this->exportsFeedback = $exportsFeedback;
        $this->canExportFeedback = $canExportFeedback;
    }


    /**
     * @param Request $request
     * @return Response
     */
    public function logic(Request $request) : BinaryFileResponse
    {
        $this->canExportFeedback->passes();

        $response = $this->exportsFeedback->download('feedback.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
        ob_end_clean();

        return $response;
    }

}
