# By: Riasat Ullah
# This file contains content for user notifications.

from translators import label_translator as _lt
from utils import constants, label_names as lbl, mail_content_labels as mcl

font_family = 'sans-serif'
header_color = '#404040'


def upcoming_on_call_email_content(lang, first_name, policy_name, level, start_time, end_time, time_zone):
    '''
    Gets the email content for an upcoming on-call email.
    :param lang: content language
    :param first_name: first name of the user
    :param policy_name: name of the group the user is going on call for
    :param level: the level the user is going on call at
    :param start_time: (datetime.time) time when the on-call routine will start
    :param end_time: (datetime.time) time when the on-call routine will end
    :param time_zone: timezone the times are bing shown in
    :return: (tuple) subject, email content
    '''
    subject = 'TaskCall: {0} - {1}'.format(_lt.get_label(mcl.mcl_body_you_are_going_on_call, lang),
                                           start_time.strftime(constants.timestamp_words_format))
    notice = '''
    <div style="font-family: {0}; font-weight: 500;">
        <p> Hi {1}, </p>
        <p>
            {2}:
            <br/><br/>
            {3}: {4} <br/>
            {5}: {6} <br/>
            {7}: {8} <br/>
            {9}: {10} <br/>
            {11}: {12} <br/>
            {13}: {14}
        </p>
    </div>
             '''.format(font_family, first_name, _lt.get_label(mcl.mcl_body_you_are_going_on_call, lang),
                        _lt.get_label(lbl.ttl_escalation_policy, lang), policy_name,
                        _lt.get_label(lbl.det_level, lang), str(level),
                        _lt.get_label(lbl.det_from, lang), start_time.strftime(constants.timestamp_words_format),
                        _lt.get_label(lbl.det_to, lang), end_time.strftime(constants.timestamp_words_format),
                        _lt.get_label(lbl.ttl_timezone, lang), time_zone,
                        _lt.get_label(lbl.det_duration, lang), str(end_time - start_time))
    return subject, notice


def upcoming_on_call_push_notice(lang, policy_name, level, start_time, end_time, time_zone):
    '''
    Gets the content for an upcoming on-call push notification.
    :param lang: content language
    :param policy_name: name of the group the user is going on call for
    :param level: the level the user is going on call at
    :param start_time: (datetime.time) time when the on-call routine will start
    :param end_time: (datetime.time) time when the on-call routine will end
    :param time_zone: timezone the times are bing shown in
    :return: (tuple) notification title, notification body
    '''
    notice_title = '{0} - {1}'.format(_lt.get_label(mcl.mcl_body_you_are_going_on_call, lang), policy_name)
    body = '{0}: {1}, {2}: {3} - {4} ({5}), {6}: {7}'.format(
        _lt.get_label(lbl.det_level, lang), str(level), _lt.get_label(lbl.det_time, lang),
        start_time.strftime(constants.timestamp_words_format), end_time.strftime(constants.timestamp_words_format),
        time_zone, _lt.get_label(lbl.det_duration, lang), str(end_time - start_time)
    )
    return notice_title, body


def ending_on_call_email_content(lang, first_name, policy_name, level, end_time, time_zone):
    '''
    Gets the email content for an upcoming on-call email.
    :param lang: content language
    :param first_name: first name of the user
    :param policy_name: name of the group the user is going on call for
    :param level: the level the user is going on call at
    :param end_time: (datetime.time) time when the on-call routine will end
    :param time_zone: timezone the times are bing shown in
    :return: (tuple) -> subject, email content
    '''
    subject = 'TaskCall - {0} {1}'.format(_lt.get_label(mcl.mcl_body_you_are_coming_off_on_call, lang), policy_name)
    notice = '''
    <div style="font-family: {0}; font-weight: 500;">
        <p> Hi {1}, </p>
        <p>
            {2}:
            <br/><br/>
            {3}: {4} <br/>
            {5}: {6} <br/>
            {7}: {8} <br/>
            {9}: {10}
    </div>
             '''.format(font_family, first_name, _lt.get_label(mcl.mcl_body_you_are_coming_off_on_call, lang),
                        _lt.get_label(lbl.ttl_escalation_policy, lang), policy_name,
                        _lt.get_label(lbl.det_level, lang), str(level),
                        _lt.get_label(lbl.det_time, lang), end_time.strftime(constants.timestamp_words_format),
                        _lt.get_label(lbl.ttl_timezone, lang), time_zone)
    return subject, notice


def ending_on_call_push_notice(lang, policy_name, level, end_time, time_zone):
    '''
    Gets the content for an upcoming on-call push notification.
    :param lang: content language
    :param policy_name: name of the group the user is going on call for
    :param level: the level the user is going on call at
    :param end_time: (datetime.time) time when the on-call routine will end
    :param time_zone: timezone the times are bing shown in
    :return: (tuple) -> notification title, notification body
    '''
    notice_title = '{0} {1}'.format(_lt.get_label(mcl.mcl_body_you_are_coming_off_on_call, lang), policy_name)
    body = '{0}: {1}, {2}: {3} ({4})'.format(
        _lt.get_label(lbl.det_level, lang), str(level), _lt.get_label(lbl.det_time, lang),
        end_time.strftime(constants.timestamp_words_format), time_zone
    )
    return notice_title, body
