import sys

class FacesRecord:
    def __init__(self, uuid, data, guest_photo, worker_photo):
        self.uuid = uuid
        self.data = data
        self.guest_photo = guest_photo
        self.worker_photo = worker_photo

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

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

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

dump_file.write("""
CREATE TABLE IF NOT EXISTS evi.faces
(
    uuid text COLLATE pg_catalog."default" NOT NULL,
    data bytea NOT NULL,
    CONSTRAINT faces_pkey PRIMARY KEY (uuid)
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS evi.faces
    OWNER to core;
\n""")

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

    cols = row.split(",")
    record = FacesRecord(cols[0], cols[1], cols[2], cols[3])

    if record.guest_photo:
        photo_uuid = record.guest_photo
    else:
        photo_uuid = record.worker_photo

    dump_file.write(f"""INSERT INTO evi.faces (uuid, data)
                     VALUES ('{photo_uuid}', '{record.data}');\n""")

