import sys

class UserRecord:
    def __init__(self, user_id, login, password, blocked, activated, role, last_contact):
        self.user_id = user_id
        self.login = login
        self.password = password
        self.blocked = blocked
        self.activated = activated
        self.role = role
        self.last_contact = last_contact

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."user"
(
    user_id text COLLATE pg_catalog."default" NOT NULL,
    login text COLLATE pg_catalog."default" NOT NULL,
    password text COLLATE pg_catalog."default" NOT NULL,
    comment text COLLATE pg_catalog."default" NOT NULL DEFAULT ''::text,
    status boolean NOT NULL DEFAULT false,
    blocked boolean NOT NULL,
    activated boolean NOT NULL DEFAULT false,
    role text COLLATE pg_catalog."default" NOT NULL,
    last_contact timestamp with time zone,
    CONSTRAINT user_pkey PRIMARY KEY (user_id),
    CONSTRAINT user_unique_login_cnt UNIQUE (login)
);
\n""")

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

    cols = row.split(",")
    record = UserRecord(cols[0], cols[1], cols[2], cols[3], cols[4], cols[5], cols[6])

    status = "f"
    comment = ""

    dump_file.write(f"""INSERT INTO evi."user" (user_id, login, password, comment, status, blocked, activated, role)
                    VALUES ('{record.user_id}', '{record.login}', '{record.password}', '{comment}', '{status}', '{record.blocked}', '{record.activated}', '{record.role}');\n""")
