"""Logic for Report Payment.""" from payment.models.report_payment import ReportPayment def create_or_update_report_payment( target_type: str, target_id: int, report_type: str, report_export_url: str, ) -> ReportPayment: """Create or update a report payment. Args: target_type (str): The type of the target. target_id (int): The ID of the target. report_type (str): The type of the report. report_export_url (str): The URL for the report. Returns: dict: The created or updated report payment. """ report_payment = ReportPayment.get_by_target_and_type( target_type=target_type, target_id=target_id, report_type=report_type ) if report_payment: report_payment.update_attributes(report_export_url=report_export_url) ReportPayment.commit_changes() else: report_payment = ReportPayment.create( target_type=target_type, target_id=target_id, report_export_url=report_export_url, report_type=report_type, ) return report_payment def get_reports_by_target( target_type: str, target_id: int, ) -> list[ReportPayment]: """Get reports by target. Args: target_type (str): The type of the target. target_id (int): The ID of the target. Returns: list: List of report payments for the specified target. """ reports = ReportPayment.get_all_by_target( target_type=target_type, target_id=target_id, ) return reports def get_report_payment(report_payment_id: int) -> ReportPayment: """Get report payment info by ID. Args: report_payment_id (int): The ID of the report payment. Returns: dict: report payment instance. """ report = ReportPayment.get_by_id_or_error(report_payment_id) return report def get_download(report_payment_id: int) -> dict: """Get download info by ID. Args: report_payment_id (int): The ID of the report payment. Returns: dict: download info. """ report = ReportPayment.get_by_id_or_error(report_payment_id) return {'download_url': report.create_presigned_url()}