#  Copyright (C) 2023
#  ABM, Moscow
#
#  UNPUBLISHED PROPRIETARY MATERIAL.
#  ALL RIGHTS RESERVED.
#
#  Authors: Vasya Svintsov <v.svintsov@techokert.ru>
from dataclasses import dataclass, field
from typing import Any

from type_cast import convert_to_type


@dataclass
class EntityOrder:
    column: str
    ascending: bool


@dataclass
class EntityOrderASC(EntityOrder):
    ascending: bool = field(init=False, default=True)


@dataclass
class EntityOrderDESC(EntityOrder):
    ascending: bool = field(init=False, default=False)


def entity_order_as_dict(order: EntityOrder) -> dict[str, Any]:
    return {key: convert_to_type(type_, key, getattr(order, key)) for key, type_ in EntityOrder.__annotations__.items()}
