#!/usr/bin/env python3
"""
CLI runner for Odoo import scripts.

Usage:
    python scripts/odoo/run_all.py --nodes
    python scripts/odoo/run_all.py --csv path/to/file.csv
"""
import argparse
import sys
from pathlib import Path

# Add parent to path for imports
sys.path.insert(0, str(Path(__file__).parent))

from client import OdooClient
from import_nodes import import_from_csv, get_transport_refs


def main():
    parser = argparse.ArgumentParser(description="Import data into Odoo")
    parser.add_argument("--nodes", action="store_true", help="Import nodes from all CSV files in datasets/")
    parser.add_argument("--csv", type=str, help="Import nodes from specific CSV file")

    args = parser.parse_args()

    # If no flags, show help
    if not any([args.nodes, args.csv]):
        parser.print_help()
        return

    # Connect to Odoo
    client = OdooClient()
    client.connect()

    refs = get_transport_refs(client)
    print(f"Transport refs: {refs}")

    if args.nodes:
        datasets_dir = Path(__file__).parent.parent.parent / "datasets"
        csv_files = list(datasets_dir.glob("*.csv"))
        for csv_path in csv_files:
            import_from_csv(client, refs, str(csv_path))

    if args.csv:
        import_from_csv(client, refs, args.csv)

    print("\n=== DONE ===")


if __name__ == "__main__":
    main()
