<?php

namespace App\Tools;

use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class ItcUniwalletNameEnquiry
{
    private string $apiUrl;

    public function __construct(){
         $this->apiUrl = 'http://5.9.86.210/pay/itc_uniwallet_name_enquiry.php';
    }
    public function apiCall($params=[]){
        try {
            $response = Http::asForm()->post($this->apiUrl,$params);

            // Handle the response data
            $statusCode = $response->status();
            $responseData = $response->body();

            $finalResponse = json_decode($responseData, true);

            $this->appLog(" Api Request | Request Type: POST | Status: ". json_encode($statusCode) ." | Endpoint: {$this->apiUrl} | Response: " . json_encode($finalResponse));
        }
        catch (\Exception $exception){
            $this->appLog(" Api Request | Request Type: POST | Status: Failed | Endpoint: {$this->apiUrl} | Response: " . json_encode($exception->getMessage()));
            $finalResponse = null;
        }

        return $finalResponse;
    }


    public function appLog($message)
    {
        Log::info("\n=============================== Logging ===============================");
        Log::info($message);
    }

}