"""Example: Using the Malware service to scan files."""

from sed_sh import SedSH
import time

# Initialize client
client = SedSH()

# Example 1: Scan a PDF file
print("=== Example 1: Scan a PDF file ===")
try:
    scan = client.malware.scan_file("/path/to/document.pdf")
    print(f"Scan ID: {scan['scanId']}")
    print(f"File name: {scan['fileName']}")
    print(f"File size: {scan['fileSize']} bytes")
    print(f"Status: {scan['status']}")
    print("You'll receive an email when the scan completes (typically 1-2 minutes)")
except FileNotFoundError:
    print("Error: File not found. Update the path to a real file.")
print()

# Example 2: Scan multiple files
print("=== Example 2: Scan multiple files ===")
files_to_scan = [
    "/path/to/file1.pdf",
    "/path/to/file2.zip",
    "/path/to/file3.exe",
]

scan_ids = []
for file_path in files_to_scan:
    try:
        scan = client.malware.scan_file(file_path)
        scan_ids.append(scan['scanId'])
        print(f"Queued: {scan['fileName']} (ID: {scan['scanId']})")
    except FileNotFoundError:
        print(f"Skipped: {file_path} (not found)")

print(f"\nTotal scans initiated: {len(scan_ids)}")
print("Email notifications will be sent as each scan completes.")
print()

# Example 3: Error handling
print("=== Example 3: Error handling ===")
try:
    # Try to scan a non-existent file
    scan = client.malware.scan_file("/path/that/does/not/exist.pdf")
except FileNotFoundError as e:
    print(f"Caught expected error: {e}")

# Example 4: Using context manager
print("\n=== Example 4: Context manager ===")
with SedSH() as client:
    try:
        scan = client.malware.scan_file("/tmp/test.pdf")
        print(f"Scan initiated: {scan['scanId']}")
    except FileNotFoundError:
        print("Update the file path to scan a real file")
