from rest_framework import serializers


def question_bank_sort_by_validator(sort_by):
    allowed_questions_sort_by_items = [
        'name_asc', 'name_desc', 'questions_count_asc', 'questions_count_desc', 'price_asc', 'price_desc', 'created_at_asc',
        'created_at_desc', 'modified_at_asc', 'modified_at_desc']
    if sort_by not in allowed_questions_sort_by_items:
        raise serializers.ValidationError(
            f'sort_by should be one of {", ".join(allowed_questions_sort_by_items)}')
    return sort_by
