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

    def list(self):
        return self.client.request("GET", "/webhooks")

    def get(self, webhook_id):
        return self.client.request("GET", f"/webhooks/{webhook_id}")

    def create(self, name, url, events, headers=None, retry_policy=None):
        data = {
            "name": name,
            "url": url,
            "events": events,
        }
        if headers:
            data["headers"] = headers
        if retry_policy:
            data["retryPolicy"] = retry_policy
        return self.client.request("POST", "/webhooks", json=data)

    def update(self, webhook_id, **kwargs):
        return self.client.request("PUT", f"/webhooks/{webhook_id}", json=kwargs)

    def delete(self, webhook_id):
        return self.client.request("DELETE", f"/webhooks/{webhook_id}")

    def test(self, webhook_id):
        return self.client.request("POST", f"/webhooks/{webhook_id}/test")

    def get_deliveries(self, webhook_id, limit=50, status=None):
        params = {"limit": limit}
        if status:
            params["status"] = status
        return self.client.request("GET", f"/webhooks/{webhook_id}/deliveries", params=params)

    def regenerate_secret(self, webhook_id):
        return self.client.request("POST", f"/webhooks/{webhook_id}/regenerate-secret")
