<?php

namespace App\Http\Controllers;

use App\Exports\CxCExport;
use App\Exports\PaymentsExport;
use App\Exports\RenewalsExport;
use App\Exports\SalesExport;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;

class ExportController extends Controller
{
    public function sales(Request $request): \Symfony\Component\HttpFoundation\BinaryFileResponse
    {
        return Excel::download(
            new SalesExport($request->only(['currency', 'payment_status', 'date_from', 'date_to'])),
            'ventas-' . now()->format('Y-m-d') . '.xlsx'
        );
    }

    public function payments(Request $request): \Symfony\Component\HttpFoundation\BinaryFileResponse
    {
        return Excel::download(
            new PaymentsExport($request->only(['currency', 'date_from', 'date_to'])),
            'pagos-' . now()->format('Y-m-d') . '.xlsx'
        );
    }

    public function cxc(Request $request): \Symfony\Component\HttpFoundation\BinaryFileResponse
    {
        return Excel::download(
            new CxCExport($request->only(['date_from', 'date_to'])),
            'cxc-' . now()->format('Y-m-d') . '.xlsx'
        );
    }

    public function renewals(): \Symfony\Component\HttpFoundation\BinaryFileResponse
    {
        return Excel::download(
            new RenewalsExport(),
            'renovaciones-' . now()->format('Y-m-d') . '.xlsx'
        );
    }
}
