"""SigningEntitySapProfitCenter marshmallow schemas.""" from abacus_common_logic.marshalling.custom_fields import ma from marshmallow import fields, validate from abacus_contract.schemas.reference_sap_profit_center import ( ReferenceSapProfitCenterSchema, ) from abacus_contract.schemas.reference_signing_entity import ( ReferenceSigningEntitySchema, ) class _BaseSigningEntitySapProfitCenterSchema(ma.Schema): """Shared fields for the SE-PC junction.""" reference_signing_entity_id = ma.IntegerId(required=True) reference_sap_profit_center_id = ma.IntegerId(required=True) class SigningEntitySapProfitCenterPostSchema(_BaseSigningEntitySapProfitCenterSchema): """POST body for creating a SE-PC junction row.""" class SigningEntitySapProfitCenterPostByProfitCenterSchema(ma.Schema): """POST body for creating one ore more SE-PC junction rows for specified profit center.""" reference_signing_entity_ids = ma.List( ma.IntegerId( required=True, validate=[validate.Range(min=1, error='ID must be greater than 0')], ) ) class SigningEntitySapProfitCenterDetailSchema(_BaseSigningEntitySapProfitCenterSchema): """Response shape for a SE-PC junction row.""" signing_entity_sap_profit_center_id = ma.IntegerId(required=True) created_at = ma.FormattedDateTime(allow_none=True) deleted_at = ma.FormattedDateTime(allow_none=True) class SigningEntitySapProfitCenterWithSigningEntitySchema(ma.Schema): """Junction row with the SE entity nested inline. Each item represents one authorization grant (a junction row). The top-level fields identify the authorization (id, when it was granted); ``signing_entity`` expands the SE that this authorization is for. """ signing_entity_sap_profit_center_id = ma.IntegerId(required=True) reference_sap_profit_center_id = ma.IntegerId(required=True) created_at = ma.FormattedDateTime(allow_none=True) signing_entity = fields.Nested(ReferenceSigningEntitySchema, required=True) class SigningEntitySapProfitCenterWithSapProfitCenterSchema(ma.Schema): """Junction row with the SAP profit center entity nested inline. Each item represents one authorization grant (a junction row). The top-level fields identify the authorization (id, when it was granted); ``sap_profit_center`` expands the PC that this authorization grants access to. """ signing_entity_sap_profit_center_id = ma.IntegerId(required=True) reference_signing_entity_id = ma.IntegerId(required=True) created_at = ma.FormattedDateTime(allow_none=True) sap_profit_center = fields.Nested(ReferenceSapProfitCenterSchema, required=True) class SigningEntitySapProfitCenterDataloaderSchema(ma.Schema): """Schema for wrapping a collection of mapped SAP Profit Centers.""" data = fields.Nested( SigningEntitySapProfitCenterWithSapProfitCenterSchema, many=True, allow_none=True, ) class SapProfitCenterSigningEntityDataloaderSchema(ma.Schema): """Schema for wrapping a collection of mapped Signing Entities.""" data = fields.Nested( SigningEntitySapProfitCenterWithSigningEntitySchema, many=True, allow_none=True, )