class Functions:
    def __init__(self, client):
        self.client = client

    def list(self, cluster_id):
        return self.client.request("GET", f"/clusters/{cluster_id}/functions")

    def get(self, cluster_id, function_id):
        return self.client.request("GET", f"/clusters/{cluster_id}/functions/{function_id}")

    def create(self, cluster_id, name, code, trigger, description=None, trigger_config=None, timeout=None, memory_limit=None, enabled=True):
        data = {
            "name": name,
            "code": code,
            "trigger": trigger,
            "enabled": enabled,
        }
        if description:
            data["description"] = description
        if trigger_config:
            data["triggerConfig"] = trigger_config
        if timeout:
            data["timeout"] = timeout
        if memory_limit:
            data["memoryLimit"] = memory_limit
        return self.client.request("POST", f"/clusters/{cluster_id}/functions", json=data)

    def update(self, cluster_id, function_id, **kwargs):
        return self.client.request("PUT", f"/clusters/{cluster_id}/functions/{function_id}", json=kwargs)

    def delete(self, cluster_id, function_id):
        return self.client.request("DELETE", f"/clusters/{cluster_id}/functions/{function_id}")

    def test(self, cluster_id, function_id, input_data=None):
        return self.client.request("POST", f"/clusters/{cluster_id}/functions/{function_id}/test", json={"input": input_data or {}})

    def execute(self, cluster_id, function_id, input_data=None, context=None):
        return self.client.request("POST", f"/clusters/{cluster_id}/functions/{function_id}/execute", json={"input": input_data or {}, "context": context or {}})

    def get_logs(self, cluster_id, function_id, limit=50):
        return self.client.request("GET", f"/clusters/{cluster_id}/functions/{function_id}/logs", params={"limit": limit})

    def get_scheduler_status(self):
        return self.client.request("GET", "/scheduler/status")
