from argparse import _SubParsersAction
from functools import partial
from typing import List
from lxml.objectify import IntElement, StringElement
from .db_object import DbObject
from .representation_row_base import RepresentationRowBase
[docs]
class AddressTypeRow(RepresentationRowBase):
# object name: type hinting = "column name in the db response"
AddressTypeID: IntElement = "AddressTypeID"
AddressTypeName: StringElement = "AddressTypeName"
[docs]
class AddressType(DbObject):
GET_BY_NAME_KEY = "AddressTypeName"
NAME = "AddressType"
REPRESENTATION_ROW_CLASS = AddressTypeRow
[docs]
def add_arguments(self, parser: _SubParsersAction):
subparser = parser.add_parser("get_address_type")
subparser.set_defaults(parser="get")
subparser.set_defaults(func=partial(self.get, serialize_for_cli=True))
[docs]
async def get(self, serialize_for_cli=False) -> List[AddressTypeRow]:
response = await self.call_hq("sdk_GetAddressType")
if serialize_for_cli:
columns = ["AddressTypeID", "AddressTypeName"]
response = self.serialize_for_cli(response, columns)
return response