"""Blueprint for Payment Allocation API.""" from http import HTTPStatus from typing import Any, Tuple from abacus_common_logic.marshalling.base import PaginationSchema from common_apispec import doc, marshal_with, use_kwargs from flask import Blueprint from payment.config import Config from payment.constants.constants import DEFAULT_BULK_MAX_LIMIT from payment.logic import payment_allocation as logic from payment.schemas.payment_allocation import ( PaymentAllocationFlowthroughBulkDeleteSchema, PaymentAllocationFlowthroughBulkRequestSchema, PaymentAllocationFlowthroughBulkUpdateSchema, PaymentAllocationFlowthroughListSchema, ) from payment.utils.authorization import check_jwt_identity payment_allocation_api = Blueprint('payment_allocation_api', __name__) @payment_allocation_api.route('/payment-allocations/flowthrough/bulk', methods=['POST']) @doc( tags=['Payment Allocation'], description='Bulk retrieval of flowthrough payment allocations.', ) @check_jwt_identity(Config.PAYMENT_ALLOCATION_IDENTITIES) @use_kwargs(PaginationSchema, location='query') @use_kwargs(PaymentAllocationFlowthroughBulkRequestSchema, location='json') @marshal_with( PaymentAllocationFlowthroughListSchema, code=HTTPStatus.OK, description=HTTPStatus.OK.phrase, ) def get_flowthrough_allocations_bulk(**params) -> Tuple[dict[str, Any], int]: """Endpoint to retrieve flowthrough payment allocations in bulk. Supports filtering by: - payment_allocation_ids: List of payment allocation IDs - contract_ids: List of contract IDs - payment_statuses: List of payment statuses - ledger_statuses: List of ledger statuses Requires pagination parameters (limit, offset). Only returns flowthrough type allocations. Excludes soft-deleted records. """ return logic.get_flowthrough_allocations_bulk(**params), HTTPStatus.OK @payment_allocation_api.route('/payment-allocations/flowthrough', methods=['PUT']) @doc( tags=['payment allocation'], description=f'Bulk update payment allocation flowthrough max ({DEFAULT_BULK_MAX_LIMIT}) items at once.', ) @check_jwt_identity(Config.PAYMENT_ALLOCATION_IDENTITIES) @use_kwargs(PaymentAllocationFlowthroughBulkUpdateSchema(many=True), location='json') @marshal_with(None, code=HTTPStatus.OK, description=HTTPStatus.OK.phrase, apply=False) def bulk_update_payment_allocations_flowthrough(*params) -> tuple: """PUT payment allocations flowthrough.""" logic.bulk_update_payment_allocations_flowthrough(params) return None, HTTPStatus.OK @payment_allocation_api.route('/payment-allocations/flowthrough', methods=['DELETE']) @doc( tags=['payment allocation'], description=f'Bulk delete payment allocation flowthrough max ({DEFAULT_BULK_MAX_LIMIT}) items at once.', ) @check_jwt_identity(Config.PAYMENT_ALLOCATION_IDENTITIES) @use_kwargs(PaymentAllocationFlowthroughBulkDeleteSchema, location='json') @marshal_with( None, code=HTTPStatus.NO_CONTENT, description=HTTPStatus.NO_CONTENT.phrase, apply=False, ) def bulk_delete_payment_allocations_flowthrough(payment_allocation_ids) -> tuple: """DELETE payment allocations flowthrough.""" logic.bulk_delete_payment_allocations_flowthrough(payment_allocation_ids) return None, HTTPStatus.NO_CONTENT