# -*- coding: utf-8 -*-
import os
import sys

import django

sys.path.append("../server")

os.environ.setdefault("IT_APP_ENVIRONMENT", "local")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.base")
django.setup()

from vbv_lernwelt.course_session.models import CourseSessionAttendanceCourse
from vbv_lernwelt.notify.email.email_services import (
    create_template_data_from_course_session_attendance_course,
    EmailTemplate,
    send_email,
)


def send_attendance_course_reminder():
    csac = CourseSessionAttendanceCourse.objects.get(pk=1)
    print(csac)
    print(csac.trainer)
    print(csac.due_date)

    result = send_email(
        recipient_email="daniel.egger+sendgrid@gmail.com",
        template=EmailTemplate.ATTENDANCE_COURSE_REMINDER,
        template_data=create_template_data_from_course_session_attendance_course(csac),
        template_language="de",
        fail_silently=False,
    )
    print(result)


def send_learning_mentor_invitation():
    result = send_email(
        recipient_email="daniel.egger+sendgrid@gmail.com",
        template=EmailTemplate.LEARNING_MENTOR_INVITATION,
        template_data={
            "inviter_name": f"Daniel Egger",
            "inviter_email": "daniel.egger@example.com",
            "target_url": f"https://stage.vbv-afa.ch/foobar",
        },
        template_language="de",
        fail_silently=True,
    )
    print(result)


def main():
    print("start")
    # send_attendance_course_reminder()
    send_learning_mentor_invitation()


if __name__ == "__main__":
    main()
