import sys
import uuid
from uuid import UUID

class VisitRecord:
    def __init__(self, visit_id, date_start, time_start, date_end, time_end):
        self.visit_id = visit_id
        self.date_start = date_start
        self.time_start = time_start
        self.date_end = date_end
        self.time_end = time_end

f = open(sys.argv[1], mode="r")

dump_file = open(sys.argv[2], mode="w")

rows = f.read().split("\n")

for row in rows:
    if len(row) == 0:
        continue

    cols = row.split(",")
    record = VisitRecord(cols[0], cols[1], cols[2], cols[3], cols[4])
    uuidv4 = str(uuid.uuid4())

    dump_file.write(f"""INSERT INTO evi.calendar (calendar_id, name, comment, type)
                    VALUES ('{record.visit_id}', '', '', 'guests');\n""")

    dump_file.write(f"""INSERT INTO evi.calendar_day_time (calendar_day_id, calendar, start_time, end_time)
                VALUES ('{uuidv4}', '{record.visit_id}', '{record.time_start}', '{record.time_end}');\n""")

    dump_file.write(f"""INSERT INTO evi.calendar_dates (calendar_day_time, date_start, date_end)
                VALUES ('{uuidv4}', '{record.date_start}', '{record.date_end}');\n""")
