<?php

namespace App\Repositories\Core\Eloquent;

use Illuminate\Http\Request;

use App\Models\Lote;
use App\Repositories\Contracts\LoteRepositoryInterface;
use App\Repositories\Core\BaseEloquentRepository;

class EloquentLoteRepository extends BaseEloquentRepository implements LoteRepositoryInterface
{
    public function entity()
    {
        return Lote::class;
    }

    public function search(Request $request)
    {
        dd($this->entity);
        return $this->entity
            ->where(function ($query) use ($request) {
                if($request->proprietario){
                    $filter = $request->proprietario;
                    $query->where(function ($querySub) use ($filter){
                        $querySub->where('proprietario', 'LIKE', "%{$filter}%");
                    })
                     ->orderBy('municipio_id', 'desc')
                     ->paginate();
                }

                // if (isset($data['municipio_id'])) {
                //     $query->where('municipio_id', $data['municipio_id']);
                // }
                // if (isset($data['proprietario'])) {
                //     $query->where('proprietario', $data['proprietario']);
                // }
            })
            ->orderBy('municipio_id', 'desc')
            ->paginate();
    }

}
