"""Reference SAP Profit Center marshmallow schema.""" from abacus_common_logic.marshalling.custom_fields import ma from marshmallow import RAISE, Schema, fields, validate from abacus_contract.constants.constants import ( DEFAULT_PAGE_LIMIT, DEFAULT_PAGE_OFFSET, SAP_PROFIT_CENTER_SORT_OPTIONS, SORT_ORDER_OPTIONS, ) class ReferenceSapProfitCenterSchema(ma.Schema): """Reference SAP Profit Center schema.""" reference_sap_profit_center_id = ma.IntegerId(required=True) profit_center = ma.NonemptyString(required=True) company_code = ma.NonemptyString(required=True) business_group = ma.NonemptyString(required=True) display_name = ma.NonemptyString(required=True) class ReferenceSapProfitCenterPutSchema(ma.Schema): """PUT body for updating a SAP profit center. Currently only display_name is mutable. The schema raises on unknown fields so adding a new mutable column is an explicit opt-in here. """ class Meta: """Reject unknown fields so the endpoint stays narrow by default.""" unknown = RAISE display_name = ma.NonemptyString(required=True) class ReferenceSapProfitCenterPostSchema(ma.Schema): """POST body for creating a SAP profit center.""" class Meta: """Reject unknown fields so the endpoint stays narrow by default.""" unknown = RAISE profit_center = ma.NonemptyString(required=True) company_code = ma.NonemptyString(required=True) business_group = ma.NonemptyString(required=True) display_name = ma.NonemptyString(required=True) reference_signing_entity_ids = ma.List(ma.IntegerId()) class ReferenceSapProfitCenterFilterSchema(ma.Schema): """Reference SAP Profit Center List filter schema.""" limit = ma.NonNegativeInteger(missing=DEFAULT_PAGE_LIMIT) offset = ma.NonNegativeInteger(missing=DEFAULT_PAGE_OFFSET) sort_by = ma.Enum( options=SAP_PROFIT_CENTER_SORT_OPTIONS, load_default=SAP_PROFIT_CENTER_SORT_OPTIONS.DISPLAY_NAME, ) sort_order = ma.Enum( options=SORT_ORDER_OPTIONS, load_default=SORT_ORDER_OPTIONS.ASC ) search_term = ma.NonemptyString( allow_none=True, ) orphan = ma.Boolean(allow_none=True) signing_entity_ids = fields.String( allow_none=True, validate=validate.Regexp( r'^\d+(?:\s*,\s*\d+)*$', error="signing_entity_ids must be a comma-separated list of numbers (e.g., '1,2,3').", ), ) class ReferenceSapProfitCenterDataloaderSchema(ma.Schema): """Schema for wrapping a collection of SAP profit center.""" data = fields.Nested( ReferenceSapProfitCenterSchema, many=True, allow_none=True, )