<?php

namespace App\Services\Banxico;

use Illuminate\Support\Facades\Http;

class BanxicoService{
    public function getSeriesData(mixed $id){
      // Control Data
        $token = config('services.banxico.token');

      // Request
        $response = Http::withHeaders([
            'Bmx-Token' => $token,
        ])->get("https://www.banxico.org.mx/SieAPIRest/service/v1/series/{$id}/datos/oportuno");

      //Response
        if($response->failed()){
            return response() -> json(
                [ 
                    'status' => 'error',
                    'message' => 'Error al conectar con el servicio de Banxico'
                ],
                $response -> status()
            );
        }

        return $response->json();
    }

}
