#!/usr/bin/env python3
"""Example: Verify multiple files and generate summary."""

import sys
from pathlib import Path

from rich.console import Console
from rich.table import Table

from synth_media_compliance_cli.processor import MediaProcessor

console = Console()


def main():
    if len(sys.argv) < 2:
        console.print("[red]Usage: verify_batch.py DIRECTORY[/red]")
        sys.exit(1)

    directory = Path(sys.argv[1])
    processor = MediaProcessor(watermark_engine=None, sign=True)

    # Find all files with signatures
    sig_files = list(directory.rglob("*.sig"))

    if not sig_files:
        console.print("[yellow]No signed files found[/yellow]")
        sys.exit(0)

    table = Table(title=f"Verification Results ({len(sig_files)} files)")
    table.add_column("File", style="cyan")
    table.add_column("Signature", style="bold")
    table.add_column("Metadata", style="bold")

    for sig_file in sig_files:
        original_file = sig_file.with_suffix("")
        if not original_file.exists():
            continue

        verification = processor.verify_file(original_file)

        sig_status = (
            "[green]✓ VALID[/green]"
            if verification["signature"]["valid"]
            else "[red]✗ INVALID[/red]"
        )
        meta_status = (
            "[green]✓ PRESENT[/green]"
            if verification["metadata"]["valid"]
            else "[yellow]○ MISSING[/yellow]"
        )

        table.add_row(original_file.name, sig_status, meta_status)

    console.print(table)


if __name__ == "__main__":
    main()
