# Generated from ANISIVO Partner API 1.0.0 (OpenAPI 3.1.0). Do not edit; run npm run partner:generate. Python SDK
import json
from urllib.request import Request, urlopen

class AnisivoClient:
    def __init__(self, base_url, token=None, clinic_id=None):
        self.base_url, self.token, self.clinic_id = base_url.rstrip('/'), token, clinic_id
    def request(self, path, method='GET', body=None):
        headers = {'Content-Type': 'application/json'}
        if self.token: headers['Authorization'] = 'Bearer ' + self.token
        if self.clinic_id: headers['X-ANISIVO-Clinic-ID'] = self.clinic_id
        payload = None if body is None else json.dumps(body).encode()
        with urlopen(Request(self.base_url + path, data=payload, headers=headers, method=method), timeout=30) as response:
            return json.loads(response.read())
    def exchange_token(self, client_id, client_secret, environment='sandbox', scope=''):
        return self.request('/oauth/token', 'POST', {'grant_type':'client_credentials','client_id':client_id,'client_secret':client_secret,'environment':environment,'scope':scope})

OPERATIONS = [{"operationId":"exchangeToken","method":"POST","path":"/oauth/token"},{"operationId":"getClinicContext","method":"GET","path":"/context"},{"operationId":"listPartnerAppointments","method":"GET","path":"/appointments"},{"operationId":"createPartnerAppointment","method":"POST","path":"/appointments"},{"operationId":"getSandboxState","method":"GET","path":"/sandbox"},{"operationId":"resetSandbox","method":"POST","path":"/sandbox"},{"operationId":"listWebhookEndpoints","method":"GET","path":"/webhooks"},{"operationId":"createWebhookEndpoint","method":"POST","path":"/webhooks"},{"operationId":"revokeWebhookEndpoint","method":"DELETE","path":"/webhooks/{endpointId}"},{"operationId":"rotateWebhookSecret","method":"POST","path":"/webhooks/{endpointId}"},{"operationId":"listWebhookDeliveries","method":"GET","path":"/webhooks/{endpointId}/deliveries"},{"operationId":"replayWebhookDelivery","method":"POST","path":"/webhooks/{endpointId}/deliveries"}]
