"""Blueprint for Worksheet Account Contract Taxable Revenue API.""" from http import HTTPStatus from typing import Optional, Tuple from abacus_common_logic.marshalling.base import PaginationSchema from common_apispec import doc, marshal_with, use_kwargs from flask import Blueprint, request, Response from owsrequest import flask_request from owsresponse import response from owsresponse.adaptors.flask import flaskify from payment.constants import constants from payment.constants.error import ERROR_CODE_AUTHORIZATION from payment.logic import worksheet_account_contract_taxable_revenue as logic from payment.schemas.worksheet_account_contract_taxable_revenue import ( TaxableRevenueCatchupFilterParamsPostSchema, WorksheetAccountContractTaxableRevenueCreateSchema, WorksheetAccountContractTaxableRevenueFilterParamsPostSchema, WorksheetAccountContractTaxableRevenueListSchema, ) from payment.utils.authorization import check_access worksheet_account_contract_taxable_revenue_api = Blueprint( 'worksheet_account_contract_taxable_revenue_api', __name__, url_prefix='/worksheet-account-contract-taxable-revenue', ) @worksheet_account_contract_taxable_revenue_api.route( '/event//bulk/', methods=['POST'], ) @doc( tags=['taxable revenue'], description='Bulk creation endpoint for worksheet_account_contract_taxable_revenue.', ) @check_access @use_kwargs( WorksheetAccountContractTaxableRevenueCreateSchema(many=True), location='json', required=True, # noqa: E501 ) @marshal_with( None, code=HTTPStatus.CREATED, description=HTTPStatus.CREATED.phrase, apply=False ) def bulk_create_worksheet_account_contract_taxable_revenue( *create_params: dict, event_id: int ) -> Tuple[dict, int] | Response: """Bulk creating worksheet_account_contract_taxable_revenue records.""" logic.bulk_create(event_id, create_params) return constants.BULK_ENDPOINT_SUCCESS_RESPONSE, HTTPStatus.CREATED @worksheet_account_contract_taxable_revenue_api.route( '/event//', methods=['DELETE'] ) @check_access @doc( tags=['taxable revenue'], description='Delete endpoint for worksheet_account_contract_taxable_revenue by event_id', # noqa: E501 ) @marshal_with( None, code=HTTPStatus.NO_CONTENT, description=HTTPStatus.NO_CONTENT.phrase, apply=False, ) def bulk_delete_worksheet_account_contract_taxable_revenue( event_id: int, ) -> Tuple[None, int] | Response: """Bulk deleting worksheet_account_contract_taxable_revenue by event_id.""" logic.bulk_delete(event_id) return None, HTTPStatus.NO_CONTENT @worksheet_account_contract_taxable_revenue_api.route( '/statement-period//', methods=['POST'], ) @doc( tags=['taxable revenue'], description='Get worksheet_account_contract_taxable_revenue list by statement_period_id and filters.', # noqa: E501 ) @check_access @use_kwargs(PaginationSchema, location='query') @use_kwargs( WorksheetAccountContractTaxableRevenueFilterParamsPostSchema, location='json' ) @marshal_with( WorksheetAccountContractTaxableRevenueListSchema, code=HTTPStatus.OK, description=HTTPStatus.OK.phrase, ) def get_worksheet_account_contract_taxable_revenue_list( statement_period_id: int, filters: Optional[dict], limit: Optional[int] = constants.DEFAULT_PAGE_LIMIT, offset: Optional[int] = constants.DEFAULT_PAGE_OFFSET, ) -> Tuple[dict, int] | Response: """List endpoint to get records by statement period and filters.""" taxable_revenue_list = logic.get_list( statement_period_id=statement_period_id, limit=limit, offset=offset, **filters ) return taxable_revenue_list, HTTPStatus.OK @worksheet_account_contract_taxable_revenue_api.route( '/catchup', methods=['POST'], ) @doc( tags=['taxable revenue'], description='Catchup taxable revenue records starting from last payment statement period.', # noqa: E501 ) @check_access @use_kwargs(PaginationSchema, location='query') @use_kwargs(TaxableRevenueCatchupFilterParamsPostSchema, location='json') @marshal_with( WorksheetAccountContractTaxableRevenueListSchema, code=HTTPStatus.OK, description=HTTPStatus.OK.phrase, ) def get_catchup_taxable_revenue_list( filters: Optional[dict], limit: Optional[int] = constants.DEFAULT_PAGE_LIMIT, offset: Optional[int] = constants.DEFAULT_PAGE_OFFSET, ) -> Tuple[dict, int] | Response: """Catchup taxable revenue records starting from last payment statement period.""" catchup_data = logic.catchup_taxable_revenue(limit=limit, offset=offset, **filters) return catchup_data, HTTPStatus.OK