# Copyright (c) 2021 CloudZero - ALL RIGHTS RESERVED - PROPRIETARY AND CONFIDENTIAL
# Unauthorized copying of this file and/or project, via any medium is strictly prohibited.
# Direct all questions to legal@cloudzero.com


from typing import List

from voluptuous import ALLOW_EXTRA, Any, Schema

from czc.api.v2.constants import (SORT_KEY_PARAMETER, SORT_ORDER_ASC,
                                  SORT_ORDER_DESC, SORT_ORDER_PARAMETER)

SORT_ORDER = Any(SORT_ORDER_ASC, SORT_ORDER_DESC)

SORTING_PARAMETERS_SCHEMA = Schema({
    SORT_KEY_PARAMETER: str,
    SORT_ORDER_PARAMETER: SORT_ORDER,
}, extra=ALLOW_EXTRA)


def sorting_parameters_schema(sort_key_values: List = None):
    if sort_key_values:
        return SORTING_PARAMETERS_SCHEMA.extend({SORT_KEY_PARAMETER: Any(*sort_key_values)})
    return SORTING_PARAMETERS_SCHEMA
