<?php

namespace App\Modules\Voip\Controllers;

use App\Modules\Voip\Services\SureVoIPAPI;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
use Illuminate\Pagination\LengthAwarePaginator;
use App\Http\Controllers\BaseController;

class VoipController extends BaseController
{
    public function index(Request $request, SureVoIPAPI $voip): \Illuminate\View\View
    {
        $response = $voip->request('partners/cassistance/customers', [], [200,201], 'GET');
        $data = $response['JSON'];
        $customers = new LengthAwarePaginator($data['list'], $data['total_entries'], $data['entries_per_page']);
        return view('voip::index', compact('customers'));
    }

    public function show($id, SureVoIPAPI $voip): \Illuminate\View\View
    {
        $response = $voip->request('partners/cassistance/customers/'.$id, [], [200,201], 'GET');
        $data = $response['JSON'];
        $response = $voip->request('partners/cassistance/customers/'.$id.'/numbers', [], [200,201], 'GET');
        $numbers = $response['JSON'];
        return view('voip::show', compact('data', 'numbers'));
    }
}
