<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Recurring;
use Illuminate\Http\Request;
use App\Services\ReportService;

class ReportController extends Controller
{
    //
    public function salesReport(Request $request)
    {
       $inputData=$this->getInputData($request->only(['clientName','fdate','tdate','pageLimit']));
       $salesData=$this->getSalesReportData($inputData);
       return view('report.sales_report',compact('salesData','inputData'));
    }
    public function recurringReport(Request $request)
    {
        $inputData=$this->getInputData($request->only(['clientName','fdate','tdate']));
        $recurringInfo=$this->getRecurringReportData($inputData);
        return view('report.recurring_list',compact('recurringInfo','inputData'));
    }
    private function  getRecurringReportData($inputData)
    {
        $recurringInfo=(new Recurring())->getTransactions($inputData);
        return $recurringInfo;
    }
    private function  getSalesReportData($inputData)
    {
        $salesData= (new ReportService())->getSalesReport($inputData);
        return $salesData;
    }
    private function getInputData($formData)
    {
        $items = empty($formData['pageLimit']) ? config('constant.PAGINATION_LIMIT'):$formData['pageLimit'];
        $fdate= (!empty($formData['fdate']))?getStringToDate($formData['fdate']):'';
        $tdate=(!empty($formData['tdate']))?getStringToDate($formData['tdate']):'';
        $clientName=(!empty($formData['clientName']))?$formData['clientName']:'';
        $inputData=['clientName'=>$clientName,'fdate'=>$fdate,'tdate'=>$tdate,'pageLimit'=>$items];
        return $inputData;
    }
}
