import abc
import typing

from abstra_internals.cloud_api.http_client import AbstraHTTPResponse, HTTPClient
from abstra_internals.environment import REQUEST_TIMEOUT


class TablesRepository(abc.ABC):
    client: "HTTPClient"

    def __init__(self, client: "HTTPClient") -> None:
        self.client = client

    def execute(self, query: str, params: typing.List) -> AbstraHTTPResponse:
        raise NotImplementedError()


class ProductionTablesRepository(TablesRepository):
    def execute(self, query: str, params: typing.List) -> AbstraHTTPResponse:
        body = {"query": query, "params": params}
        return self.client.post(
            "/tables/execute",
            json=body,
        )


class LocalTablesRepository(TablesRepository):
    def execute(self, query: str, params: typing.List) -> AbstraHTTPResponse:
        body = {"query": query, "params": params}

        return self.client.post("/tables/execute", json=body, timeout=REQUEST_TIMEOUT)
