# -*- coding: utf-8 -*-
"""
Module api_model.py 
---------------------
    Defines the base class to the resource body.
"""
from simple_mappers import MapDefinition


class ApiModel(MapDefinition):
    """An base ApiModel.
    ApiModel defines the structure of the resources body message.
    """
    def __init__(self, map_undefined=False, **kwargs):
        super().__init__(map_undefined, **kwargs)

    @classmethod
    def to_swagger(cls, spec):
        """
        A Model class to swagger schema serialization.
        :param spec: A dict object used to store and represent the swagger specification.
        """
        model_schema = dict()

        model_schema["type"] = "object"
        model_schema["properties"] = dict()
        for property_name, property_def in cls.__properties__.items():
            # TODO MAPPING_NAME
            p_name = property_name if property_def.mapping_from is None else property_def.mapping_from
            model_schema["properties"][p_name] = property_def.to_swagger(dict())
        spec.definitions[cls.__name__] = model_schema
        return spec



