"""VendorRestrictedFeatures schemas.""" from marshmallow import Schema, ValidationError, fields, validates from account.constants import error from account.constants.features import FEATURES class BulkAddVendorRestrictedFeaturesSchema(Schema): """Bulk add VendorRestrictedFeatures schema. Properties: -vendor_id (int): Vendor ID. -feature_ids (list[int]): list of Feature IDs. """ vendor_id = fields.Integer(required=True) feature_ids = fields.List(fields.Integer(), required=True) @validates('feature_ids') def validate_feature_ids(self, feature_ids_raw, **kwargs): valid_feature_ids = set(x.value for x in FEATURES) for feature_id in feature_ids_raw: if int(feature_id) not in valid_feature_ids: raise ValidationError( error.ERROR_MESSAGE_FEATURE_NOT_FOUND.format(feature_id=feature_id) ) return True class BulkRemoveVendorRestrictedFeaturesSchema(BulkAddVendorRestrictedFeaturesSchema): """Bulk remove VendorRestrictedFeatures schema."""