"""
Models for the site.

:copyright: Copyright 2013-2017, Dorian Pula <dorian.pula@amber-penguin-software.ca>
:license: AGPL v3+
"""

import copy

from rookeries import database


class Site(database.DatabaseModel):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.name = kwargs.get('name', 'Rookeries')
        self.menu = kwargs.get('menu', [])
        # TODO: Come up with nicer way to check both snake and camel case opts
        self.landing_page = kwargs.get(
            'landing_page', kwargs.get('landingPage'))

        # TODO: Deprecate configuration
        self.config = kwargs.get('config', {})

    @staticmethod
    def doc_type():
        return 'site'

    def _json_repr(self):
        return {
            'name': self.name,
            'config': self.config,
            'menu': self.menu,
            'landingPage': self.landing_page,
        }

    def to_api_json(self):
        api_json = copy.deepcopy(self._json_repr())
        # TODO: Add a better way to render based on api endpoints
        api_json['links'] = {'self': '/api/site'}
        return api_json

    def to_db_json(self):
        db_json = copy.deepcopy(self._json_repr())
        return self.attach_db_metadata(db_json)
