"""Schemas for worksheet_account_contract_payable_details records processing.""" from abacus_common_logic.marshalling.base import PaginationSchema from abacus_common_logic.marshalling.custom_fields import ma from abacus_common_logic.marshalling.helpers import MarshmallowSchemaFactory from marshmallow import validate, validates_schema, ValidationError from payment.constants.constants import DEFAULT_BULK_MAX_LIMIT from payment.constants.error import ERROR_BULK_MAX_LIMIT class WorksheetAccountContractPayableDetailsCreateSchema(ma.Schema): """Creation data validation schema.""" worksheet_account_contract_payable_after_tax_id = ma.NonNegativeInteger( required=True ) account_id = ma.NonNegativeInteger(required=True) contract_id = ma.NonNegativeInteger(required=True) target_table = ma.NonemptyString(required=True) target_id = ma.NonNegativeInteger(required=True) reference_target_table = ma.String(required=False, allow_none=True) reference_target_id = ma.NonNegativeInteger(required=False, allow_none=True) payable_detail_type_id = ma.NonNegativeInteger(required=False, allow_none=True) amount_payable = ma.Decimal(as_string=True, required=True) currency = ma.NonemptyString(required=True) notes = ma.String(required=False, allow_none=True) class WorksheetAccountContractPayableDetailsDetailSchema( WorksheetAccountContractPayableDetailsCreateSchema ): """ Schema for Worksheet Account Contract Payable Details. This schema defines the structure for the Worksheet Account Contract Payable Details. It specifies the required fields and their data types for the existing records. Attributes: worksheet_account_contract_payable_details_id (int): The ID of worksheet payable details worksheet_account_contract_payable_after_tax_id (int): The ID of the worksheet contract_id (int): The ID of the contract. account_id (int): The ID of the account. statement_period_id (int): The ID of the statement period. target_table (str): Table name. target_id (int): The ID of the table. reference_target_table (str): Reference table name. reference_target_id (int): The ID of the reference table. payable_detail_type_id (decimal): The ID of the reference payable detail type. currency (str): The currency code. amount_payable (decimal): The payable amount. notes (str): The notes. """ # noqa: E501 worksheet_account_contract_payable_details_id = ma.NonNegativeInteger(required=True) statement_period_id = ma.NonNegativeInteger(required=True) class PaginatedWorksheetAccountContractPayableDetailsOutputSchema(PaginationSchema): """ Schema for Paginated Worksheet Account Contract Payable Details. This schema defines the structure and validation rules for the Paginated Worksheet Account Contract Payable Details. It specifies the required fields and their data types. Attributes: items (List[WorksheetAccountContractPayableDetailsCreateSchema]): The list of Worksheet Account Contract Payable Details. total_count (int): The total count of Worksheet Account Contract Payable Details. """ # noqa: E501 items = ma.Nested( WorksheetAccountContractPayableDetailsDetailSchema, many=True, example=MarshmallowSchemaFactory( WorksheetAccountContractPayableDetailsDetailSchema, many=True ).dump( [ { 'worksheet_account_contract_payable_details_id': 1, 'worksheet_account_contract_payable_after_tax_id': 1, 'account_id': 1, 'contract_id': 1, 'statement_period_id': 1, 'target_table': 'some_table_1', 'target_id': 1, 'reference_target_table': 'some_target_table_1', 'reference_target_id': 1, 'payable_detail_type_id': 1, 'amount_payable': 1.00, 'currency': 'USD', 'notes': 'some notes', }, { 'worksheet_account_contract_payable_details_id': 2, 'worksheet_account_contract_payable_after_tax_id': 2, 'account_id': 2, 'contract_id': 2, 'statement_period_id': 2, 'target_table': 'some_table_2', 'target_id': 2, 'payable_detail_type_id': 2, 'amount_payable': 2.00, 'currency': 'USD', }, ] ), ) total_count = ma.NonNegativeInteger(required=True, example=2) class FilterKeySchema(ma.Schema): """Filter key for filtering.""" worksheet_payable_after_tax_ids = ma.List(ma.NonNegativeInteger(), required=False) detail_groups = ma.List(ma.NonemptyString(), required=False) class PayableDetailsBulkFilterKeySchema(ma.Schema): """Filter key for bulk payable details filtering.""" payment_group_payment_account_ids = ma.List( ma.NonNegativeInteger(), required=True, validate=[validate.Length(min=1)] ) payable_detail_type_ids = ma.List(ma.NonNegativeInteger(), required=False) class PayableDetailsBulkFilterParamsPostSchema(ma.Schema): """Post request params for bulk payable details filtering.""" filters = ma.Nested( PayableDetailsBulkFilterKeySchema, required=True, ) class WorksheetAccountContractPayableDetailsBulkDeleteSchema(ma.Schema): """Schema for bulk soft deleting worksheet_account_contract_payable_details \ by worksheet_account_contract_payable_after_tax_id.""" worksheet_account_contract_payable_after_tax_ids = ma.List( ma.NonNegativeInteger(required=True), required=True, validate=[validate.Length(min=1)], ) @validates_schema def validate_schema(self, data, **kwargs): ids = data.get('worksheet_account_contract_payable_after_tax_ids') or [] if len(ids) > DEFAULT_BULK_MAX_LIMIT: raise ValidationError(ERROR_BULK_MAX_LIMIT.format(DEFAULT_BULK_MAX_LIMIT)) return data