<?php

namespace App\Http\Controllers;

use App\Models\Cliente;
use Exception;
use Illuminate\Http\Request;

class ClienteController extends Controller
{


    public function status(){
        return ['status'=>'Ok'];
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Cliente  $cliente
     * @return \Illuminate\Http\Response
     */
    public function show(Cliente $cliente)
    {
            
        

             $cliente=Cliente::join('users','clientes.usuario_id','=','users.id')->join('pessoas','pessoas.id','=','users.pessoa_id')->select('clientes.*','pessoas.nome')->orderBy('pessoas.nome','Asc')->get();
             $count=0;
             $data = array();
             foreach($cliente as $cli){

                 $cli->getUser;
                 array_push($data, [
                    //$cli->id,
                    //$cli->numerocliente,
                    $cli->getUser->id,
                    $cli->getUser->name,
                    //$cli->getUser->getPessoa->nome,
                 ]);
                // "id"  $cli->id,
                // "numero" => $cli->numerocliente,
                // "name" =>$cli->getUser->name,
                // "nome" =>$cli->getUser->getPessoa->nome,
                 $count++;
             }
             return json_encode($data);
              //$data;
             //return $cliente->toJson();
        

    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\Cliente  $cliente
     * @return \Illuminate\Http\Response
     */
    public function edit(Cliente $cliente)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Cliente  $cliente
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Cliente $cliente)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Cliente  $cliente
     * @return \Illuminate\Http\Response
     */
    public function destroy(Cliente $cliente)
    {
        //
    }
}
