"""Edit UserSubscription schema.""" from typing import Any from marshmallow import Schema, ValidationError, fields, validates_schema class EditUserSubscription(Schema): """Edit UserSubscription schema. Properties: - follow_all_resources (bool): True if we will auto follow all resources. - follow_resources (list): List of resource uuids if we follow selected resources. - automatic (bool): False when it is called from user actions. - overwrite (bool): True if existing resources should be unfollowed first before following follow_resources. """ follow_all_resources = fields.Boolean(required=False) follow_resources = fields.List(fields.String, required=False) automatic = fields.Boolean(required=False) overwrite = fields.Boolean(required=False) @validates_schema def validate_data(self, data: dict[str, Any], **kwargs: Any) -> None: """Extra schema level validation.""" # We can have follow_all_resources=false, to indicate toggle OFF if ( not data.get('follow_all_resources') and not data.get('follow_resources') and data.get('follow_all_resources', None) is not False ): raise ValidationError('Either follow_all_resources or follow_resources is required.')