<?php

namespace App\Controllers\User;

use App\Controllers\BaseController;

use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\API\ResponseTrait;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use Config\Services;

class UserController extends BaseController
{
    
    public function __construct(){
        
        helper(['url', 'form']);
        
    }
    
    public function user_profile()
    {
        $jwtToken = session('jwt_token');
        $userId = session('user_id');

        if (!$jwtToken || !$userId) {
            return $this->response->setJSON([
                'status' => 401,
                'message' => 'Unauthorized',
            ]);
        }

       
        // Call external/internal API with token
        $client = \Config\Services::curlrequest();
        $response = $client->get('https://localhost/barasatgmch/api/user/userdetails', [
            'headers' => [
                'Authorization' => 'Bearer ' . $jwtToken,
                'Accept'        => 'application/json',
            ],
            'query' => [
                'user_id' => $userId
            ],
            'verify' => false // for self-signed SSL
        ]);
      
        $data = json_decode($response->getBody(), true);
       

        return view('user/profile', [
            'page_title' => 'Profile || ',
            'apiData'    => $data
        ]);
    }



}
