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

import requests as requests_http
from . import utils
from sdk.models import operations, shared
from typing import Optional

class Wallets:
    r"""Everything about Wallet collection
    https://doc.getlago.com/docs/api/wallets/wallet-object - Find out more
    """
    _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 create(self, request: shared.WalletInput) -> operations.CreateWalletResponse:
        r"""Create a new wallet
        Create a new wallet
        """
        base_url = self._server_url
        
        url = base_url.removesuffix('/') + '/wallets'
        
        headers = {}
        req_content_type, data, form = utils.serialize_request_body(request, "request", 'json')
        if req_content_type not in ('multipart/form-data', 'multipart/mixed'):
            headers['content-type'] = req_content_type
        if data is None and form is None:
            raise Exception('request body is required')
        
        client = self._security_client
        
        http_res = client.request('POST', url, data=data, files=form, headers=headers)
        content_type = http_res.headers.get('Content-Type')

        res = operations.CreateWalletResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
        
        if http_res.status_code == 200:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.Wallet])
                res.wallet = out
        elif http_res.status_code == 400:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseBadRequest])
                res.api_response_bad_request = out
        elif http_res.status_code == 401:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseUnauthorized])
                res.api_response_unauthorized = out
        elif http_res.status_code == 422:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseUnprocessableEntity])
                res.api_response_unprocessable_entity = out

        return res

    def create_transaction(self, request: shared.WalletTransactionInput) -> operations.CreateWalletTransactionResponse:
        r"""Create a new wallet transaction
        Create a new wallet transaction
        """
        base_url = self._server_url
        
        url = base_url.removesuffix('/') + '/wallet_transactions'
        
        headers = {}
        req_content_type, data, form = utils.serialize_request_body(request, "request", 'json')
        if req_content_type not in ('multipart/form-data', 'multipart/mixed'):
            headers['content-type'] = req_content_type
        if data is None and form is None:
            raise Exception('request body is required')
        
        client = self._security_client
        
        http_res = client.request('POST', url, data=data, files=form, headers=headers)
        content_type = http_res.headers.get('Content-Type')

        res = operations.CreateWalletTransactionResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
        
        if http_res.status_code == 200:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.WalletTransactions])
                res.wallet_transactions = out
        elif http_res.status_code == 400:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseBadRequest])
                res.api_response_bad_request = out
        elif http_res.status_code == 401:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseUnauthorized])
                res.api_response_unauthorized = out
        elif http_res.status_code == 422:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseUnprocessableEntity])
                res.api_response_unprocessable_entity = out

        return res

    def destroy(self, request: operations.DestroyWalletRequest) -> operations.DestroyWalletResponse:
        r"""Delete a wallet
        Delete a wallet
        """
        base_url = self._server_url
        
        url = utils.generate_url(operations.DestroyWalletRequest, base_url, '/wallets/{id}', request)
        
        
        client = self._security_client
        
        http_res = client.request('DELETE', url)
        content_type = http_res.headers.get('Content-Type')

        res = operations.DestroyWalletResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
        
        if http_res.status_code == 200:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.Wallet])
                res.wallet = out
        elif http_res.status_code == 401:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseUnauthorized])
                res.api_response_unauthorized = out
        elif http_res.status_code == 404:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseNotFound])
                res.api_response_not_found = out
        elif http_res.status_code == 405:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseNotAllowed])
                res.api_response_not_allowed = out

        return res

    def find(self, request: operations.FindWalletRequest) -> operations.FindWalletResponse:
        r"""Find wallet
        Return a wallet
        """
        base_url = self._server_url
        
        url = utils.generate_url(operations.FindWalletRequest, base_url, '/wallets/{id}', request)
        
        
        client = self._security_client
        
        http_res = client.request('GET', url)
        content_type = http_res.headers.get('Content-Type')

        res = operations.FindWalletResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
        
        if http_res.status_code == 200:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.Wallet])
                res.wallet = out
        elif http_res.status_code == 401:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseUnauthorized])
                res.api_response_unauthorized = out
        elif http_res.status_code == 404:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseNotFound])
                res.api_response_not_found = out

        return res

    def find_all(self, request: operations.FindAllWalletsRequest) -> operations.FindAllWalletsResponse:
        r"""Find wallets
        Find all wallets for certain customer
        """
        base_url = self._server_url
        
        url = base_url.removesuffix('/') + '/wallets'
        
        query_params = utils.get_query_params(operations.FindAllWalletsRequest, request)
        
        client = self._security_client
        
        http_res = client.request('GET', url, params=query_params)
        content_type = http_res.headers.get('Content-Type')

        res = operations.FindAllWalletsResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
        
        if http_res.status_code == 200:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.Wallets])
                res.wallets = out
        elif http_res.status_code == 401:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseUnauthorized])
                res.api_response_unauthorized = out

        return res

    def find_all_transactions(self, request: operations.FindAllWalletTransactionsRequest) -> operations.FindAllWalletTransactionsResponse:
        r"""Find wallet transactions
        Find all wallet transactions for certain wallet
        """
        base_url = self._server_url
        
        url = utils.generate_url(operations.FindAllWalletTransactionsRequest, base_url, '/wallets/{id}/wallet_transactions', request)
        
        query_params = utils.get_query_params(operations.FindAllWalletTransactionsRequest, request)
        
        client = self._security_client
        
        http_res = client.request('GET', url, params=query_params)
        content_type = http_res.headers.get('Content-Type')

        res = operations.FindAllWalletTransactionsResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
        
        if http_res.status_code == 200:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.WalletTransactions])
                res.wallet_transactions = out
        elif http_res.status_code == 401:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseUnauthorized])
                res.api_response_unauthorized = out
        elif http_res.status_code == 404:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseNotFound])
                res.api_response_not_found = out

        return res

    def update(self, request: operations.UpdateWalletRequest) -> operations.UpdateWalletResponse:
        r"""Update an existing wallet
        Update an existing wallet
        """
        base_url = self._server_url
        
        url = utils.generate_url(operations.UpdateWalletRequest, base_url, '/wallets/{id}', request)
        
        headers = {}
        req_content_type, data, form = utils.serialize_request_body(request, "wallet_update_input", 'json')
        if req_content_type not in ('multipart/form-data', 'multipart/mixed'):
            headers['content-type'] = req_content_type
        if data is None and form is None:
            raise Exception('request body is required')
        
        client = self._security_client
        
        http_res = client.request('PUT', url, data=data, files=form, headers=headers)
        content_type = http_res.headers.get('Content-Type')

        res = operations.UpdateWalletResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
        
        if http_res.status_code == 200:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.Wallet])
                res.wallet = out
        elif http_res.status_code == 400:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseBadRequest])
                res.api_response_bad_request = out
        elif http_res.status_code == 401:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseUnauthorized])
                res.api_response_unauthorized = out
        elif http_res.status_code == 404:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseNotFound])
                res.api_response_not_found = out
        elif http_res.status_code == 422:
            if utils.match_content_type(content_type, 'application/json'):
                out = utils.unmarshal_json(http_res.text, Optional[shared.APIResponseUnprocessableEntity])
                res.api_response_unprocessable_entity = out

        return res

    