#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import datetime

if len(sys.argv) != 2:
    print("Usage: mkfile.py <filename>")
    sys.exit(1)

filename = sys.argv[1]

# create header file
with open(f"./include/solution/{filename.lower()}.h", "w") as f:
    f.write("// This file is generated by mkfile.py\n")
    f.write(f"// Date: {datetime.datetime.now().strftime('%Y-%m-%d')}\n\n")
    f.write(f"#ifndef INC_{filename.upper()}_H\n")
    f.write(f"#define INC_{filename.upper()}_H\n")
    f.write("#ifdef __cplusplus\n")
    f.write("extern \"C\"\n")
    f.write("{\n")
    f.write("#endif\n\n")
    f.write("#ifdef __cplusplus\n")
    f.write("}\n")
    f.write("#endif\n")
    f.write(f"#endif // INC_{filename.upper()}_H\n")
    f.close()

# create source file
with open(f"./src/{filename.lower()}.c", "w") as f:
    f.write("// This file is generated by mkfile.py\n")
    f.write(f"// Date: {datetime.datetime.now().strftime('%Y-%m-%d')}\n\n")
    f.write(f'#include <solution/{filename.lower()}.h>\n')
    f.close()

# create test file
with open(f"./tests/test_{filename.lower()}.cpp", "w") as f:
    f.write("// This file is generated by mkfile.py\n")
    f.write(f"// Date: {datetime.datetime.now().strftime('%Y-%m-%d')}\n\n")
    f.write(f'#include <solution/{filename.lower()}.h>\n')
    f.write("#include <gtest/gtest.h>\n")
    f.close()