"""Ledger Adjustment Handler.""" from fastapi import APIRouter from moneyhub.logic import ledger_adjustment as logic from moneyhub.schemas.ledger_adjustment import LedgerAdjustmentAppliedSchema from moneyhub.schemas.ledger_adjustment import LedgerAdjustmentSchema from moneyhub.schemas.reference_adjustment_type import ReferenceAdjustmentType ledger_adjustment_router = APIRouter(prefix='/ledger-adjustments', tags=['ledger_adjustments']) @ledger_adjustment_router.get( '/account/{account_id}', status_code=200 ) def get_ledger_adjustments_by_account_id( account_id: int, contract_id: int | None = None, statement_period_id_start: int | None = None, statement_period_id_end: int | None = None, adjustment_type_id: int | None = None ) -> list[LedgerAdjustmentSchema]: """GET ledger adjustments for a specified account. Args: account_id (int): The id of an account contract_id (int): the id of a contract statement_period_id_start (int): the id of the start of a statement period statement_period_id_end (int): the id of the end of a statement period adjustment_type_id (int): the id of the adjustment_type Returns: list: list of ledger adjustments """ return logic.get_by_account_id( account_id, contract_id, statement_period_id_start, statement_period_id_end, adjustment_type_id ) @ledger_adjustment_router.get( '/account/{account_id}/types', status_code=200 ) def get_ledger_adjustments_types_by_account_id(account_id: int) -> list[ReferenceAdjustmentType]: """GET associated adjustments types for adjustments for a given account. Args: account_id (int): ID of an account Returns: list: list of adjustments types """ return logic.get_ledger_adjustments_types_by_account_id(account_id) @ledger_adjustment_router.get( '/account/{account_id}/statement-period/{statement_period_id}', status_code=200 ) def get_adjustments_by_account_and_statement_period( account_id: int, statement_period_id: int, contract_id: int | None = None ) -> LedgerAdjustmentAppliedSchema | None: """GET ledger adjustments for a specified account. Args: account_id (int): The id of an account statement_period_id (int): The id of the statement period contract_id (int): the id of a contract Returns: LedgerAdjustmentAppliedSchema: ledger adjustments """ result = logic.get_adjustments_by_account_and_statement_periods( account_id, contract_id, [statement_period_id] ) return result[0] if result else None