#!/usr/bin/env python3
"""
Command-line interface for LLM Redact
"""

import argparse
import sys
from llm_redact.client import LLMRedactClient


def main():
    """Main CLI entry point"""
    parser = argparse.ArgumentParser(
        description=("Privacy-first text redaction using local LLM models "
                     "(Python 3.12.4+)")
    )
    parser.add_argument(
        "text", 
        help="Text to redact"
    )
    parser.add_argument(
        "--host",
        default="http://localhost:8000",
        help="LLM host URL (default: http://localhost:8000)"
    )
    parser.add_argument(
        "--model",
        help="LLM model to use"
    )
    parser.add_argument(
        "--generate-rules",
        help="Generate custom rules based on this prompt"
    )
    parser.add_argument(
        "--version",
        action="version",
        version="llm-redact 0.1.0 (Python 3.12.4+)"
    )

    args = parser.parse_args()

    try:
        client = LLMRedactClient(llm_host_url=args.host)
        
        # Generate rules if requested
        rules = None
        if args.generate_rules:
            print(f"Generating rules for: {args.generate_rules}")
            rules = client.generate_rules(args.generate_rules)
            print(f"Generated {len(rules)} rules")
        
        # Redact text
        result = client.mask(args.text, rules=rules, model=args.model)
        
        print("Original:", args.text)
        print("Redacted:", result.redacted_text)
        print(f"Processing time: {result.processing_time_ms}ms")
        print(f"Replacements: {len(result.replacements)}")
        
    except Exception as e:
        print(f"Error: {e}", file=sys.stderr)
        sys.exit(1)


if __name__ == "__main__":
    main() 