"""Blueprint for Worksheet Tax Correction VAT 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, Response from payment.constants import constants from payment.logic import worksheet_tax_correction_vat as logic from payment.schemas.worksheet_tax_correction_vat import ( WorksheetTaxCorrectionsVATDeleteSchema, WorksheetTaxCorrectionsVATFilterParamsPostSchema, WorksheetTaxCorrectionsVATListSchema, WorksheetTaxCorrectionVATCreateSchema, ) from payment.utils.authorization import check_access worksheet_tax_correction_vat_api = Blueprint( 'worksheet_tax_correction_vat_api', __name__, url_prefix='/tax-corrections/vat', ) @worksheet_tax_correction_vat_api.route( '/bulk/', methods=['POST'], ) @doc( tags=['tax correction VAT'], description='Bulk creation endpoint for worksheet_tax_correction_vat.', ) @check_access @use_kwargs( WorksheetTaxCorrectionVATCreateSchema(many=True), location='json', required=True ) @marshal_with( None, code=HTTPStatus.CREATED, description=HTTPStatus.CREATED.phrase, apply=False ) def bulk_create_worksheet_tax_correction_vat( *create_params: dict, ) -> Tuple[dict, int] | Response: """Bulk creating worksheet_tax_correction_vat records.""" logic.bulk_create(create_params) return constants.BULK_ENDPOINT_SUCCESS_RESPONSE, HTTPStatus.CREATED @worksheet_tax_correction_vat_api.route( f'//', methods=['POST'], ) @doc( tags=['tax correction VAT'], description='List endpoint for worksheet_tax_correction_vat.', ) @check_access @use_kwargs(PaginationSchema, location='query') @use_kwargs(WorksheetTaxCorrectionsVATFilterParamsPostSchema, location='json') @marshal_with( WorksheetTaxCorrectionsVATListSchema, code=HTTPStatus.OK, description=HTTPStatus.OK.phrase, ) def get_tax_corrections_vat( correction_status: str, filters: Optional[dict], limit: Optional[int] = constants.DEFAULT_PAGE_LIMIT, offset: Optional[int] = constants.DEFAULT_PAGE_OFFSET, ) -> Tuple[dict, int] | Response: """Get tax corrections VAT.""" tax_corrections = logic.get_tax_corrections_vat( correction_status=correction_status, limit=limit, offset=offset, **filters, ) return tax_corrections, HTTPStatus.OK @worksheet_tax_correction_vat_api.route( '/bulk/', methods=['DELETE'], ) @check_access @doc( tags=['tax correction VAT'], description='Delete endpoint for worksheet_tax_correction_vat', ) @use_kwargs(WorksheetTaxCorrectionsVATDeleteSchema, location='json', required=True) @marshal_with( None, code=HTTPStatus.NO_CONTENT, description=HTTPStatus.NO_CONTENT.phrase, apply=False, ) @marshal_with( None, code=HTTPStatus.BAD_REQUEST, description=HTTPStatus.BAD_REQUEST.phrase, ) def delete_tax_corrections_vat( worksheet_tax_correction_vat_ids, ) -> Tuple[None, int] | Response: """Bulk deleting worksheet_tax_correction_vat by list of ids.""" logic.delete_worksheet_tax_corrections_vat( worksheet_tax_correction_vat_ids=worksheet_tax_correction_vat_ids ) return None, HTTPStatus.NO_CONTENT