"""Generate 1998 CSV files (0.csv..1997.csv) with realistic TLS data matching TlsDB.csv.

Usage: runtime\python\python.exe scripts\gen_1998_files.py [--rows-per-file N] [--output-dir DIR]
"""
import random, csv, argparse
from pathlib import Path
from datetime import datetime, timedelta
from gen_test_data import generate_row, COLUMNS as columns

random.seed(42)

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--rows-per-file', type=int, default=5, help='Rows per CSV file')
    parser.add_argument('--output-dir', type=str, default='data/multi_upload')
    args = parser.parse_args()

    out_dir = Path(args.output_dir)
    out_dir.mkdir(parents=True, exist_ok=True)
    total = 1998
    base_time = datetime(2026, 6, 1, 0, 0, 0)

    for i in range(total):
        filepath = out_dir / f'{i}.csv'
        with open(filepath, 'w', newline='', encoding='utf-8') as f:
            writer = csv.DictWriter(f, fieldnames=columns)
            writer.writeheader()
            for j in range(args.rows_per_file):
                row_time = base_time + timedelta(seconds=random.randint(0, 86400 * 30))
                row = generate_row(i * args.rows_per_file + j, row_time)
                writer.writerow(row)

    print(f'Generated {total} files × {args.rows_per_file} rows = {total * args.rows_per_file} total rows')
    print(f'Output: {out_dir.resolve()}')

if __name__ == '__main__':
    main()
