<?php

namespace App\Http\Controllers\Api\Elementos;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;
use App\Danoral\Elementos\ElementoSearch;
use App\Http\Resources\Elemento as ElementoResources;


class ElementoSearchController extends Controller
{
    protected $elementoSearch;

    public function __construct(ElementoSearch $elementoSearch)
    {
        $this->elementoSearch = $elementoSearch;
    }

    public function search(Request $request){
        $strSearch = $request->str;
        $iEL = $this->elementoSearch->search($strSearch);
        return response()->json(ElementoResources::collection($iEL),200);
    }

    public function cli(Request $request) {
        $strCLI = $request->str;
        $dateCobro = date("Y-m-d");
        if(isset($request->dateCobro)){
            $dateCobro = $request->dateCobro;
        }
        $res = ElementoSearch::searchCLI($strCLI, $dateCobro);
        return response()->json($res, 200);

    }
}
