#!/usr/bin/env python3

import os
import shutil
from os import path
from string import Template

cd = path.dirname(path.abspath(__file__))
contexts = {
    "batch": {
        "view_type": "view",
    },
    "streaming": {
        "view_type": "materialized view",
    },
}

file_head = """# This file is generated by `gen.py`. Do not edit it manually!"""


def render(filename: str):
    print(f"Rendering `{filename}`...")
    name = path.splitext(filename)[0]

    with open(path.join(cd, filename), "r") as f:
        tpl = Template(f.read())

    for mode, context in contexts.items():
        out_file = path.join(cd, f"{name}.{mode}")
        with open(out_file, "w") as f:
            f.write(file_head + "\n\n")
            f.write(tpl.safe_substitute(context))


for filename in os.listdir(cd):
    if not filename.endswith(".slt.template"):
        continue
    render(filename)


print("Done.")
