#!/usr/bin/env python3
"""Blur client names in image - v2 with corrected coordinates."""

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-v2.jpg"

img = Image.open(input_path)
w, h = img.size
print(f"Image size: {w}x{h}")

# All client names to blur - recalculated for 986x1600
# Looking at the image structure more carefully
blur_regions = [
    # Line: "*Phat Foods:* Week 1 deliverables..."
    (30, 128, 250, 175),
    
    # Line: "*Spoken:* Dovi remarks review..."  
    (30, 185, 580, 230),
    
    # Line: "*General:* SparkBeyond, White Space, Finally Foods"
    (175, 240, 680, 290),
    
    # Header: "*1. Phat Foods Deadline Approaching*"
    (15, 385, 590, 435),
    
    # Header: "*2. Spoken Project (Dovi Remarks)*"
    (15, 540, 605, 595),
    
    # Line: "1. *Phat Foods check-in*"
    (45, 1025, 390, 1080),
    
    # Line: "2. *Complete Dovi review*"
    (45, 1095, 400, 1145),
]

result = img.copy()

for i, region in enumerate(blur_regions):
    x1, y1, x2, y2 = region
    x1 = max(0, x1)
    y1 = max(0, y1)
    x2 = min(w, x2)
    y2 = min(h, y2)
    
    cropped = img.crop((x1, y1, x2, y2))
    blurred = cropped.filter(ImageFilter.GaussianBlur(radius=25))
    result.paste(blurred, (x1, y1))
    print(f"Region {i+1}: ({x1}, {y1}, {x2}, {y2})")

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