<?php

namespace App\Http\Controllers\Exports;


use App\Classes\Modules\Exports\Services\ExportsCustomers;
use App\Classes\Modules\Exports\Services\ExportsTransactions;
use App\Classes\Modules\Exports\Services\ExportsNullDebtors;
use App\Classes\Modules\Exports\Services\ExportsPaymentTransactions;

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

class ExportCustomersToExcelController
{

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

    public function export(ExportsCustomers $exportsCustomers, Request $request){
        return $exportsCustomers->download('customers.csv', Excel::CSV, ['Content-Type' => 'text/csv']);
    }

    public function transactions(ExportsTransactions $exportsTransactions, Request $request){
        return $exportsTransactions->download('transactions.csv', Excel::CSV, ['Content-Type' => 'text/csv']);
    }

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

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

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