"""Requests to ows-moneyhub.""" from src.connectors.ows_service import OwsService from src.utils.dataclasses import StatementAttachmentPayload class OwsMoneyhub(OwsService): """OwsMoneyhub client for fetching requests.""" _service = 'ows-moneyhub' @classmethod def get_account_statement_period_vat( cls, account_id: int, contract_id: int, statement_period_id: int ) -> dict: """Get VAT info for an account, contract, and statement period. Args: account_id (int): ID of the account. contract_id (int): ID of the contract. statement_period_id (int): ID of the statement period. Returns: dict: VAT info """ path = f'/account/{account_id}/statement-period/{statement_period_id}/vat' return cls.validate_response_type(cls.get(path, params={'contract_id': contract_id}), dict) @classmethod def get_statement_attachment(cls, statement_attachment_id: int) -> dict: """Get a statement attachment by its ID. Args: statement_attachment_id (int): ID of the attachment Returns: dict: The attachment """ path = f'/statement-attachment/{statement_attachment_id}' return cls.validate_response_type(cls.get(path), dict) @classmethod def get_statement_attachments( cls, account_id: int, statement_period_id: int, subaccount_id: int | None ) -> list[dict]: """Get Statement attachments by specified account and statement period. Args: account_id (int): ID of the Account statement_period_id (int): ID of the Statement Period subaccount_id (int): Optional subaccount ID to filter by Returns: list[dict]: List of the attachments related to the account and the period. """ params = {} if subaccount_id is not None: params['subaccount_id'] = subaccount_id path = f'/statement-attachment/account/{account_id}/statement-period/{statement_period_id}' return cls.validate_response_type(cls.get(path, params), list) @classmethod def update_statement_attachment( cls, statement_attachment_id: int, payload: StatementAttachmentPayload ) -> dict: """PUT request to update Statement attachment's file location value. Args: statement_attachment_id (int): ID of the Statement Attachment payload (dict): Fields to update Returns: dict: Updated Statement Attachment object. """ path = f'/statement-attachment/{statement_attachment_id}' payload_serialised = payload.__dict__ return cls.validate_response_type(cls.put(path, payload_serialised), dict) @classmethod def get_reference_signing_entity(cls, contract_id: int) -> dict: """Get Reference Signing Entity by specified contract. Args: contract_id (int): ID of the contract Returns: dict: Reference Signing Entity object. """ path = f'/reference-signing-entity/contract/{contract_id}' return cls.validate_response_type(cls.get(path), dict) @classmethod def get_ledger_vat_summary( cls, account_id: int, contract_id: int, statement_period_id: int, vat_categories: list ) -> list[dict]: """GET vat summary for a specified account, contract, statement period and vat category(s). Args: account_id (int): The id of an account contract_id (int): ID of the Contract statement_period_id (int): The id of statement period vat_categories (list): Vat categories to filter Returns: list: list of ledger vat info """ vat_categories_str = ','.join(vat_categories) path = f'/ledger-vat-summary/account/{account_id}/activity-statement-period/{statement_period_id}' # noqa: E501 return cls.validate_response_type( cls.get( path, params={'contract_id': contract_id, 'vat_categories': vat_categories_str} ), list, )