#!/usr/bin/env python3
import csv
import sys
from pathlib import Path

def dedupe_csv(input_path: Path, output_path: Path, encoding="utf-8", newline=""):
    with input_path.open('r', encoding=encoding, newline=newline) as fin, \
         output_path.open('w', encoding=encoding, newline=newline) as fout:
        reader = csv.reader(fin)
        writer = csv.writer(fout)

        try:
            header = next(reader)
        except StopIteration:
            # Empty input -> empty output
            return

        writer.writerow(header)

        last_row = None
        for row in reader:
            # row is a list of strings; exact comparison
            if last_row is None or row != last_row:
                writer.writerow(row)
                last_row = row
            # else: duplicate; skip

def main():
    if len(sys.argv) < 3:
        print("Usage: no_duplicates_csv.py <input.csv> <output.csv>")
        print("Notes:")
        print("  - Assumes input is pre-sorted so duplicates are adjacent.")
        print("  - Keeps only the first row in any run of identical rows (full-row match).")
        print("  - Header row is preserved.")
        sys.exit(1)

    inp = Path(sys.argv[1])
    outp = Path(sys.argv[2])
    dedupe_csv(inp, outp)

if __name__ == "__main__":
    main()
