# -*- coding: utf-8 -*-
"""Module for Application storage."""
import logging
from collections import namedtuple
from ..signals import (
    pre_create_instance, post_create_instance,
    pre_update_instance, post_update_instance,
    pre_delete_instance, post_delete_instance,
)
from .idgenerators import UUIDGenerator
from .driver import PersistentDict
from ..exceptions import DoesNotExistException, TooManyEntriesException
from .strategies import SaveStrategy, GetStrategy, SoftDeleteStrategy
from .query import Query


# pylint: disable=too-few-public-methods
class InternalModelContructor(object):
    """Serializer raw data from storage to model.

    For internal use only.
    """

    def __init__(self, strategy):
        """Create new constructor."""
        self.strategy = strategy

    def __call__(self, raw_data, model_class):
        """Return barely wrapping raw_data with model_class."""
        return model_class(raw_data)


# pylint: disable=too-few-public-methods
class ModelContructor(InternalModelContructor):
    """Serializer raw data from storage to model."""

    def __call__(self, raw_data, model_class):
        """Call strategy to retrieve complete model tree."""
        model = super(ModelContructor, self).__call__(raw_data, model_class)
        return self.strategy.get(model)


Strategies = namedtuple('Strategies', ('getter', 'saver', 'deleter'))


class ApplicationStorage(object):
    """Storage for user data."""

    path = '{application_directory}/storage'
    defaultstorage = list
    logger = logging.getLogger(__name__)

    def __init__(self, command, save_strategy=None,
                 get_strategy=None, delete_strategy=None, **kwargs):
        """Create new storage for application."""