from rest_framework import serializers
from utils import conf
from . import conf as institute_conf


def access_sort_by_validator(sort_by):
    """
    This function checks the validity of incoming sort_by for Access records.
    """
    allowed_access_sort_by_items = ['inst_name_asc', 'inst_name_desc',
                                    'inst_created_asc', 'inst_created_desc', 'email_asc', 'email_desc']
    if sort_by not in allowed_access_sort_by_items:
        raise serializers.ValidationError(f'sort_by should be one of {", ".join(allowed_access_sort_by_items)}')
    return sort_by


def institute_student_sort_by_validator(sort_by):
    """
    This function checks the validity of incoming sort_by for InstituteStudent records.
    """
    allowed_access_sort_by_items = ['first_name_asc', 'first_name_desc', 'last_name_asc', 'last_name_desc', 'email_asc', 'email_desc',
                                    'referer_institute_student_identity_asc', 'referer_institute_student_identity_desc', 'id_asc', 'id_desc']
    if sort_by not in allowed_access_sort_by_items:
        raise serializers.ValidationError(
            f'sort_by should be one of {", ".join(allowed_access_sort_by_items)}')
    return sort_by


def institute_sort_by_validator(sort_by):
    """
    This function checks the validity of incoming sort_by for Institute records.
    """
    allowed_institute_sort_by_items = [
        'inst_name_asc', 'inst_name_desc', 'inst_created_asc', 'inst_created_desc']
    if sort_by not in allowed_institute_sort_by_items:
        raise serializers.ValidationError(
            f'sort_by should be one of {", ".join(allowed_institute_sort_by_items)}')
    return sort_by


