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

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

    def list_by_collection(self, cluster_id, collection_name):
        return self.client.request("GET", f"/clusters/{cluster_id}/collections/{collection_name}/triggers")

    def create(self, cluster_id, collection_name, name, event, code, enabled=True):
        data = {
            "collectionName": collection_name,
            "name": name,
            "event": event,
            "code": code,
            "enabled": enabled,
        }
        return self.client.request("POST", f"/clusters/{cluster_id}/triggers", json=data)

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

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