<?php

namespace App\Development\Compute;

use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;

// Compute microservice mock (ComputeController) - a customer's BGP peers and their live sessions.
class Peers
{
    // The customer's configured BGP peers, paged to the DataTables window.
    public function peers(array $params, Request $request)
    {
        $data = json_decode(file_get_contents(app_path('Development/Compute/Peers.json')));

        return Http::response(json_encode(array_slice($data, request('start', 0), request('length', 10))), 200);
    }

    /*
     * Live BGP session states across the fleet. get_peers joins these to the peers by
     * "as{asn}_v{4,6}_{ip}" to work out how many of each peer's sessions are up.
     */
    public function sessions(array $params, Request $request)
    {
        return Http::response(json_decode(file_get_contents(app_path('Development/Compute/Sessions.json')), true), 200);
    }
}
