# -*- coding: utf-8 -*-

from json import JSONEncoder

from typing import Dict, Any

from ._Course import Course


class ProductionModelJsonEncoder(JSONEncoder):
    def default(self, o):
        instances_dictionary = {
            Course: self._get_course_json
        }

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

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

    @staticmethod
    def _get_course_json(o):
        # type: (Course) -> Dict[str, Any]

        return {
            "id": o.course_id,
            "name": o.name,
            "description": o.description,
            "abbreviation": o.abbreviation,
            "delay": o.delay
        }
