from datetime import datetime
from pathlib import Path

import jinja2


class TemplateRender:
    def __init__(self) -> None:
        self.env = jinja2.Environment(loader=jinja2.FileSystemLoader(Path.cwd() / "public" / "templates"))
        self.t_test = self.env.get_template("test.j2")
        self.t_2fa_otp = self.env.get_template("2fa-otp.j2")

    def render_test(self, site_name: str) -> str:
        return self.t_test.render(site_name=site_name, sent_time=datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

    def render_2fa_otp(
        self,
        site_name: str,
        site_url: str,
        email_reason: str,
        otp_number: str,
    ) -> str:
        return self.t_2fa_otp.render(
            site_name=site_name,
            site_url=site_url,
            email_reason=email_reason,
            otp_number=otp_number,
            sent_time=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        )


template_render = TemplateRender()
