""":mod:`news.mapping` --- Reporter mapping
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Provides a mapping classes that maps from schedule to reporter classes.

"""
import copy
from .models.abstract import AbstractSchedule
from .reporters.abstract import Reporter
from .reporters.url import URLReporter
from .reporters.feed import (
    AtomReporter,
    RSSReporter
)


def merge_kwargs_factories(kwargs_factories):
    """Merge news type keyed kwargs factory functions into a single factory.

    :param kwargs_factories: A dictionary of news type keyed kwargs factory
        functions.
    :type kwargs_factories: :class:`dict`
    :returns: A merged kwargs factory.
    :rtype: A factory function that takes an schedule and returns kwargs dict.

    """
    def merged_factory(schedule):
        try:
            return kwargs_factories[schedule.type](schedule)
        except KeyError:
            return {}

    return merged_factory


class Mapping(object):
    """Mapping from news type/schedule to reporter classes.

    Implements :meth:`__setitem__` and :meth:`__getitem__` magic methods to
    support both mapping from :class:`str` and from