<?php

namespace App\Http\Controllers\Exports;

use App\Classes\Modules\Exports\Services\ExportsArrivedParcel;
use App\Classes\Modules\Exports\Services\ExportsParcel;
use App\Classes\Modules\Exports\Services\ExportsWarehousePackingList;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Excel;

class ExportArrivedParcelController
{
    /**
     * ExportArrivedParcelController constructor.
     * @param Request $request
     */
    public function __construct(Request $request)
    {
        $token = Auth::fromUser(User::find(1));
        $request->headers->set('Authorization', 'Bearer '.$token);
    }

    public function export(Request $request) {
        $exportsPendingArrangementDeliveryList = new ExportsArrivedParcel($request);
        $response = $exportsPendingArrangementDeliveryList->download('arrived-parcel.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
        ob_end_clean();
        return $response;
    }

    public function summary(Request $request) {
        $exportsParcelsSummary = new ExportsParcel();
        $response = $exportsParcelsSummary->download('parcel-summary.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
        ob_end_clean();
        return $response;
    }

    public function guangZhou2ToJohor(Request $request) {
        $exportsWarehousePackingList = new ExportsWarehousePackingList();
        $response = $exportsWarehousePackingList->download('guangzhou2-to-johor-summary.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
        ob_end_clean();
        return $response;
    }
}
