""" Interface to the ows-account microservice. The model is responsible to make a call to a ows-account microservice. It makes a request to ows-account endpoint ('/subaccount/', methods=['GET']) and returns a result of the request. """ from owsrequest import request from contracts import response ACCOUNT_OWNERSHIP_RESOURCE = '/subaccount/{subaccount_id}' ACCOUNT_VENDOR_UUID_RESOURCE = '/lookup/vendors/vendor-ids/' ACCOUNT_SERVICE = 'ows-account' def get_vendor_id_by_subaccount_id(subaccount_id): """Get vendor id by subaccount_id. Fetch vendor information by performing a GET call to ows-account (see: GET /subaccount/ endpoint). Args: subaccount_id (int): uid of a subaccount. Returns: response.Response: vendor_id (int) if available. """ resource = ACCOUNT_OWNERSHIP_RESOURCE.format(subaccount_id=subaccount_id) account_response = request.get(ACCOUNT_SERVICE, resource) if account_response.status_code == 200: return response.Response(account_response.json()['vendor_id']) return response.Response( errors=account_response.content, status=account_response.status_code ) def get_vendor_uuid_by_vendor_id(vendor_id: int) -> dict | None: """Get vendor uuid by vendor_id. Fetch vendor information by performing a POST call to ows-account (see: GET /lookup/vendors/vendor-ids/ endpoint). Args: vendor_id (int): unique identifier for the vendor Returns: response.Response: vendor_id and UUID if found. """ json_data = {'vendor_ids': [vendor_id]} ows_account_response = request.post( ACCOUNT_SERVICE, ACCOUNT_VENDOR_UUID_RESOURCE, json=json_data, ) if ows_account_response.status_code == 200: vendor = ows_account_response.json().get('vendors', [{}])[0] if vendor: return { 'vendor_id': vendor.get('vendor_id'), 'vendor_uuid': vendor.get('uuid'), } return None