<?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\ExportsBookingTransactions;
use App\Classes\Modules\Exports\Services\ExportsLeadsTransactions;
use App\Classes\Modules\Exports\Services\ExportsNullDebtors;
use App\Classes\Modules\Exports\Services\ExportsPaymentTransactions;
use App\Classes\Modules\Exports\Services\ExportsWalletTransactions;
use App\Classes\Modules\Exports\Services\ExportsInvoiceTransactions;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Excel;
use App\Classes\Modules\Exports\Services\ExportsImportedInvoiceMappeds;
use App\Models\TransactionMappingLog;
use App\Classes\Modules\Exports\Services\ExportsReceiptTransactions;

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;
    }

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

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

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

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

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