<?php


namespace App\Classes\Modules\Transactions\ControllersLogic;

use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transactions\Services\ListsTransactions;
use App\Http\Resources\MappableTransactionWithDetailsResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Carbon\Carbon;

class ListMappableTransactionWithDetailsLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Retrieved Transactions With Details',
            'message' => 'You have successfully retrieved a list of transactions'
        ];
    }


    /** @var ListsTransactions */
    private $listsTransactions;

    /**
     * ListTransactionsLogic constructor.
     * @param ListsTransactions $listsTransactions
     */
    public function __construct(ListsTransactions $listsTransactions)
    {
        $this->listsTransactions = $listsTransactions;
    }



    public function logic(Request $request) : JsonResponse
    {
        $filePath     = storage_path('logs/list_mappable_transaction_with_details.log');
        $textToAppend = Carbon::now()->format('[Y-m-d H:i:s]') . ' ' . $request->input('filters') . PHP_EOL;
        
        file_put_contents($filePath, $textToAppend, FILE_APPEND);

        $query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($request->input('filters')));

        return $this->collectionResponse(MappableTransactionWithDetailsResource::collection($query));

    }



}
