"""Blueprint for Payment Group API.""" from http import HTTPStatus import typing from abacus_common_logic.marshalling.base import PaginationSchema from common_apispec import doc, marshal_with, use_kwargs from flask import Blueprint from payment.logic import payment_group as logic from payment.schemas.payment_group import ( PaymentGroupDetailSchema, PaymentGroupListSchema, PaymentGroupPostResponseSchema, PaymentGroupPostSchema, PaymentGroupPutSchema, ) from payment.utils.authorization import check_access payment_group_api = Blueprint('payment_group_api', __name__) @payment_group_api.route('/payment-group/', methods=['POST']) @doc( tags=['Payment Group'], description='Create payment_group.', ) @check_access @use_kwargs( PaymentGroupPostSchema(exclude=('payment_group_id',)), location='json', ) @marshal_with( PaymentGroupPostResponseSchema, code=HTTPStatus.CREATED, description=HTTPStatus.CREATED.phrase, ) def create_payment_group(**params) -> typing.Tuple[dict[str, typing.Any], int]: """Endpoint to create payment group.""" return logic.create_payment_group(**params), HTTPStatus.CREATED @payment_group_api.route('/payment-group/', methods=['GET']) @doc( tags=['Payment Group'], description='Get payment_group.', ) @check_access @marshal_with( PaymentGroupDetailSchema, code=HTTPStatus.OK, description=HTTPStatus.OK.phrase ) def get_payment_group(object_id: int) -> typing.Tuple[dict[str, typing.Any], int]: """Endpoint to GET payment group by id.""" return logic.get_payment_group(object_id), HTTPStatus.OK @payment_group_api.route('/payment-group/reusable-groups/', methods=['GET']) @doc( tags=['Payment Group'], description='Get reusable payment groups.', ) @check_access @use_kwargs(PaginationSchema, location='query') @marshal_with( PaymentGroupListSchema, code=HTTPStatus.OK, description=HTTPStatus.OK.phrase, ) def get_reusable_payment_groups( limit: int, offset: int, ): """Endpoint to GET reusable payment groups.""" return logic.get_reusable_payment_groups(limit, offset), HTTPStatus.OK @payment_group_api.route('/payment-group/', methods=['PUT']) @doc( tags=['Payment Group'], description='Update payment_group.', ) @check_access @use_kwargs( PaymentGroupPutSchema, location='json', ) @marshal_with( PaymentGroupDetailSchema, code=HTTPStatus.OK, description=HTTPStatus.OK.phrase ) def update_payment_group(object_id: int, **params: dict[str, typing.Any]): """Endpoint to update PaymentGroup.""" return logic.update_payment_group(object_id, **params), HTTPStatus.OK