import json
from pathlib import Path
import sys

def check_json_files(directory):
    directory = Path(directory)

    if not directory.is_dir():
        print(f"Error: '{directory}' is not a valid directory.")
        return

    all_valid = True

    for file_path in directory.iterdir():
        if file_path.is_file():
            try:
                with file_path.open("r", encoding="utf-8") as f:
                    json.load(f)
                print(f"✓ {file_path.name}: Valid JSON")
            except json.JSONDecodeError as e:
                print(f"✗ {file_path.name}: Invalid JSON ({e})")
                all_valid = False
            except Exception as e:
                print(f"✗ {file_path.name}: Error reading file ({e})")
                all_valid = False

    if all_valid:
        print("\nAll files contain valid JSON.")
    else:
        print("\nSome files contain invalid JSON or could not be read.")

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print(f"Usage: python {sys.argv[0]} <directory>")
        sys.exit(1)

    check_json_files(sys.argv[1])