from json import JSONEncoder
from typing import (
    Any,
    Dict,
)

from ._Order import Order
from ._OrderPicture import OrderPicture
from ._TablePicture import TablePicture
from ._PaymentPicture import PaymentPicture


class OrderJsonEncoder(JSONEncoder):
    def default(self, o):
        instances_dictionary = {
            Order: self._get_order_json,
            OrderPicture: self._get_order_picture_json,
            TablePicture: self._get_table_picture_json,
            PaymentPicture: self._get_payment_picture_json,
        }

        if type(o) in instances_dictionary:
            return instances_dictionary[type(o)](o)

        return super(OrderJsonEncoder, self).default(o)

    @staticmethod
    def _get_order_json(
        o,  # type: Order
    ):
        # type: (...) -> Dict[str, Any]

        return {
            "orderPicture": o.order_picture,
            "tablePicture": o.table_picture,
            "paymentPicture": o.payment_picture,
        }

    @staticmethod
    def _get_order_picture_json(
        o,  # type: OrderPicture
    ):
        # type: (...) -> Dict[str, Any]

        return {
            "storeCode": o.store_code,
            "orderInfo": o.order_info,
        }

    @staticmethod
    def _get_table_picture_json(
        o,  # type: TablePicture
    ):
        # type: (...) -> Dict[str, Any]

        return {
            "storeCode": o.store_code,
            "tableInfo": o.table_info,
        }

    @staticmethod
    def _get_payment_picture_json(
        o,    # type: PaymentPicture
    ):
        # type: (...) -> Dict[str, Any]

        return {
            "storeCode": o.store_code,
            "paymentInfo": o.payment_info,
        }
