#!/usr/bin/env python3
"""Blur client names in image. Image is 986x1600."""

from PIL import Image, ImageFilter
import os

input_path = "/Users/assafdagan/.clawdbot/media/inbound/f01c84e1-5f12-4bcf-bfb8-257edba844eb.jpg"
output_path = "/Users/assafdagan/clawd/output/blurred-status.jpg"

img = Image.open(input_path)
print(f"Image size: {img.size}")

# Client names to blur - coordinates for 986x1600 image
# Identified names: Phat Foods, Spoken, SparkBeyond, White Space, Finally Foods, Dovi
blur_regions = [
    # "Phat Foods:" in Active Projects line 1
    (30, 115, 280, 160),
    # "Spoken:" in Active Projects line 2 
    (30, 175, 210, 215),
    # "SparkBeyond, White Space, Finally Foods" in General line
    (200, 245, 730, 290),
    # "1. Phat Foods Deadline Approaching" header
    (30, 355, 560, 405),
    # "2. Spoken Project (Dovi Remarks)" header
    (30, 500, 590, 545),
    # "Dovi" in the Spoken project section text - appears again
    # (scanning for additional Dovi mentions)
    # "1. Phat Foods check-in" in Tomorrow's Priorities
    (60, 820, 360, 865),
    # "2. Complete Dovi review" in Tomorrow's Priorities  
    (60, 875, 390, 920),
]

result = img.copy()

for region in blur_regions:
    x1, y1, x2, y2 = region
    # Make sure coordinates are within bounds
    x1 = max(0, x1)
    y1 = max(0, y1)
    x2 = min(img.size[0], x2)
    y2 = min(img.size[1], y2)
    
    cropped = img.crop((x1, y1, x2, y2))
    blurred = cropped.filter(ImageFilter.GaussianBlur(radius=20))
    result.paste(blurred, (x1, y1))
    print(f"Blurred region: {region}")

os.makedirs(os.path.dirname(output_path), exist_ok=True)
result.save(output_path, quality=95)
print(f"\nSaved to: {output_path}")
