from security.token_manager import TokenManager
import network_constants

from typing import List
import json, requests

class RestFetcher:
    def fetch_schema_information(self, use_case: str) -> List:
        jwt_token = TokenManager.getInstance().getToken()
        
        # query tables for use-case
        url = f'https://{network_constants.BUSINESS_LOGIC_HOSTNAME}:{network_constants.BUSINESS_LOGIC_REST_PORT}/api/use-cases/{use_case}/tables'
        response = requests.get(
                url,
                verify = False, 
                proxies = { "http":None, "https":None },
                headers = { "Authorization": f"Bearer {jwt_token}"}
        )

        if response.status_code != 200:
            raise ValueError(f"Error while retrieving schema information.\tStatus-code:{response.status_code}")

        tables = json.loads(response.text)
        return tables
