"""Invoice handler.""" from fastapi import APIRouter from fastapi import Depends from fastapi import Header from moneyhub.constants.constants import JWTKeys from moneyhub.logic import statement_attachment_invoice as logic from moneyhub.schemas import StatementAttachmentDetailSchema from moneyhub.schemas import StatementAttachmentInvoiceDetailSchema from moneyhub.utils.request import extract_token invoice_router = APIRouter(prefix='/invoices', tags=['invoices']) @invoice_router.get( '/statement-period/{statement_period_id}', status_code=200 ) def get_invoice_statement_attachments( statement_period_id: int, payment_entity_id: int ) -> list[StatementAttachmentInvoiceDetailSchema]: """GET all invoice types for a specified payment entity id and statement period. Args: payment_entity_id (int): The id of a payment entity statement_period_id (int): the id of a statement period Returns: list: list of invoice statement attachments """ return logic.get_invoices_by_payment_entity( payment_entity_id, statement_period_id) @invoice_router.post( '/payment-entity/{payment_entity_id}/statement-period/{statement_period_id}', status_code=201 ) def create_invoice_statement_attachments( payment_entity_id: int, statement_period_id: int, profile_dict: dict = Depends(extract_token), correlation_id: str | None = Header(None) ) -> list[StatementAttachmentDetailSchema]: """Create invoices for a payment entity and statement period. Args: payment_entity_id (int): The id of a payment entity statement_period_id (int): Period to make the report for profile_dict (dict): Profile details correlation_id (str): Request correlation ID Returns: list: List of created statement attachments """ orchard_identity_id = profile_dict[JWTKeys.ORCHARD_IDENTITY_ID] return logic.create_invoice_documents( payment_entity_id, statement_period_id, orchard_identity_id, correlation_id ) @invoice_router.post( '/payment-entity/{payment_entity_id}/statement-period/{statement_period_id}/retry', status_code=201 ) def retry_invoice_statement_attachments( payment_entity_id: int, statement_period_id: int, correlation_id: str | None = Header(None) ) -> list[StatementAttachmentDetailSchema]: """Retry creating failed invoices for a payment entity and statement period. Args: payment_entity_id (int): The id of a payment entity statement_period_id (int): Period to make the report for correlation_id (str): Request correlation ID Returns: list: List of created statement attachments """ return logic.retry_invoice_documents( payment_entity_id, statement_period_id, correlation_id )