"""Interface to the ows-collaborator microservice.""" from owsrequest import flask_request, request from royalties.connectors.sentry import send_to_sentry SERVICE_NAME = 'ows-collaborator' def close_bulk_dp_collaborator_statements( period_name, new_abacus_statement_period_id ) -> None: """Close the statement period for all Direct Payments (DP) collaborators in bulk.""" try: res = request.put( SERVICE_NAME, '/statement-period/bulk-close', headers=flask_request.get_ows_headers(), json={ 'period_name': period_name, 'direct_payments_enabled': True, 'new_abacus_statement_period_id': new_abacus_statement_period_id, }, ) if res.status_code != 204: send_to_sentry( message='Error closing bulk DP collaborator statements', errors=res.text, status=res.status_code, sentry_message=( f'Error closing bulk DP collaborator statements: ' f'{res.status_code} - {res.text}' ), ) except Exception as e: send_to_sentry( message='Error closing bulk DP collaborator statements', errors=str(e), status=500, sentry_message=f'Error closing bulk DP collaborator statements: {str(e)}', )