import sys

class CarRecord:
    def __init__(self, car_id, license_plate, color, locked):
        self.car_id = car_id
        self.license_plate = license_plate
        self.color = color
        self.locked = locked

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 evi.car
    (
        car_id text COLLATE pg_catalog."default" NOT NULL,
        license_plate text COLLATE pg_catalog."default" NOT NULL,
        country text COLLATE pg_catalog."default" NOT NULL,
        color text COLLATE pg_catalog."default" NOT NULL,
        analytics boolean NOT NULL,
        comment text COLLATE pg_catalog."default"
    );
\n""")

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

    cols = row.split(",")
    record = CarRecord(cols[0], cols[1], cols[2], cols[3])
    analytics = f"False" if record.locked == "t" else "True"

    country = "ru"
    comment = "NULL"
    dump_file.write(f"""INSERT INTO evi.car (car_id, license_plate, country, color, analytics, comment)
                    VALUES ('{record.car_id}', '{record.license_plate}', '{country}', '{record.color}', '{analytics}', {comment});\n""")
