"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""

import requests as requests_http
from . import utils
from klarna.models import operations

class Authorizations:
    r"""Operations related to authorizations"""
    _client: requests_http.Session
    _security_client: requests_http.Session
    _server_url: str
    _language: str
    _sdk_version: str
    _gen_version: str

    def __init__(self, client: requests_http.Session, security_client: requests_http.Session, server_url: str, language: str, sdk_version: str, gen_version: str) -> None:
        self._client = client
        self._security_client = security_client
        self._server_url = server_url
        self._language = language
        self._sdk_version = sdk_version
        self._gen_version = gen_version
        
    def cancel(self, request: operations.CancelAuthorizationRequest) -> operations.CancelAuthorizationResponse:
        r"""Cancel an existing authorization
        Use this API call to cancel/release an authorization. If the `authorization_token` received during a Klarna Payments won’t be used to place an order immediately you could release the authorization.
        Read more on **[Cancel an existing authorization](https://docs.klarna.com/klarna-payments/other-actions/cancel-an-authorization/)**.
        """
        base_url = self._server_url
        
        url = utils.generate_url(operations.CancelAuthorizationRequest, base_url, '/payments/v1/authorizations/{authorizationToken}', request)
        
        
        client = self._security_client
        
        http_res = client.request('DELETE', url)
        content_type = http_res.headers.get('Content-Type')

        res = operations.CancelAuthorizationResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
        

        return res

    