from datetime import datetime


def _tokenize_reddit_post_pieces(encoder, subreddit=None, date=None, title=None, selftext=None, body=None,
                                 max_date_length=1536, max_subreddit_length=1536, max_title_length=1536,
                                 max_selftext_length=1536, max_body_length=1536):
    """
    Returns a dictionary of fields that are all tokenized
    :param encoder:
    :param subreddit:
    :param date:  IS A DATETIME OBJECT
    :param title:
    :param selftext:
    :param body:
    :param max_date_length:    Defaults to a really HIGH length.
    :param max_subreddit_length:   Defaults to a really HIGH length.
    :param max_title_length:   Defaults to a really HIGH length.
    :param max_selftext_length:   Defaults to a really HIGH length.
    :param max_body_length:   Defaults to a really HIGH length.
    :return: those fields, tokenized.
    """
    article_pieces = {}
    if date is not None:
        if not isinstance(date, datetime):
            raise ValueError("Date must be a datetime obj. Provided {}".format(date))

        date_txt = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
                    'August', 'September', 'October', 'November', 'December'][date.month - 1] + ' {}, {}'.format(
            date.day, date.year)
        article_pieces['date'] = [encoder.begin_date] + encoder.encode(date_txt)[:max_date_length] + [encoder.end_date]

    if subreddit is not None:
        article_pieces['subreddit'] = [encoder.begin_domain] + encoder.encode(subreddit)[:max_subreddit_length] + [
            encoder.end_domain]

    if title is not None:
        article_pieces['title'] = [encoder.begin_title] + encoder.encode(title)[:max_title_length] + [encoder.end_title]

    if selftext is not None:
        article_pieces['selftext'] = [encoder.begin_article] + encoder.encode(selftext)[:max_selftext_length] + [
            encoder.end_article]

    if body is not None:
        article_pieces['body'] = [encoder.begin_summary] + encoder.encode(body)[:max_body_length] + [
            encoder.end_summary]
    return article_pieces