#!/usr/bin/env python3
"""Generate Olevia logos inspired by Ayoh! brand DNA."""
import os, json, requests, base64, time
from pathlib import Path

API_KEY = os.environ["RECRAFT_API_KEY"]
BASE = "https://external.api.recraft.ai/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
OUT = Path("/root/.openclaw/workspace/public/phat-foods/logos")
OUT.mkdir(parents=True, exist_ok=True)

def generate(prompt, filename, style="digital_illustration"):
    print(f"  {filename}...")
    body = {"prompt": prompt, "style": style, "model": "recraftv3", "size": "1024x1024"}
    try:
        r = requests.post(f"{BASE}/images/generations", headers=HEADERS, json=body, timeout=120)
        if r.status_code != 200:
            print(f"    ERR {r.status_code}: {r.text[:200]}")
            return None
        data = r.json()
        if "data" in data and len(data["data"]) > 0:
            img_url = data["data"][0].get("url")
            if img_url:
                img_r = requests.get(img_url, timeout=60)
                if img_r.status_code == 200:
                    (OUT / filename).write_bytes(img_r.content)
                    print(f"    OK ({len(img_r.content)} bytes)")
                    return filename
        return None
    except Exception as e:
        print(f"    {e}")
        return None

# Ayoh! DNA applied to Olevia:
# - Custom bold rounded wordmark, compact, energetic
# - Deep olive green, warm gold, cream backgrounds
# - Heavy weight, rounded terminals, hand-lettered feel
# - Tight letterspacing, functions as single graphic block
# - Premium-casual: sophisticated but warm

prompts = [
    # 1. Bold rounded custom wordmark (closest to Ayoh! DNA)
    ("Custom hand-lettered bold wordmark logo 'Olevia' on deep olive green background (#2D4A22). Heavy weight rounded letterforms with soft terminals, slightly playful but refined. White text. Compact tight letterspacing, works as single graphic block. Premium food brand like artisanal mayo or olive oil. Energetic and confident. Professional brand identity design.", 
     "ayoh-olevia-1-bold-green.png"),
    
    # 2. Same energy, cream background
    ("Custom bold hand-lettered wordmark 'Olevia' on warm cream background (#FFF8E7). Chunky rounded sans-serif letterforms, heavy weight, soft rounded terminals. Deep olive green color (#2D4A22). Tight tracking, compact word. Premium food ingredient brand. Confident, warm, Mediterranean. Professional logo design.",
     "ayoh-olevia-2-cream.png"),
    
    # 3. With olive-shaped O
    ("Custom bold wordmark logo 'Olevia' where the letter O is shaped like an olive fruit. Heavy rounded sans-serif letterforms, deep olive green (#556B2F) on white background. Warm gold accent (#D4A017) on the olive detail. Tight letterspacing. Premium Mediterranean food brand. Bold, playful, sophisticated. Professional brand identity.",
     "ayoh-olevia-3-olive-o.png"),
    
    # 4. Condensed bold (Ayoh! display type DNA)
    ("Bold condensed custom wordmark 'OLEVIA' in all caps. Extra heavy weight, tight tracking, slightly rounded terminals. Deep olive green (#2D4A22) on black background (#1A1A1A). Dramatic editorial food brand aesthetic. Like a poster for premium olive oil. Fills the frame confidently. Professional brand identity.",
     "ayoh-olevia-4-condensed-dark.png"),
    
    # 5. Warm terracotta variation
    ("Custom bold rounded wordmark 'Olevia' on warm cream background (#FFF8E7). Heavy weight with soft organic letterforms. Rich terracotta color (#C75B12). Tight compact letterspacing. Mediterranean warmth, premium artisanal food brand. Confident and inviting. Professional logo design.",
     "ayoh-olevia-5-terracotta.png"),
    
    # 6. Full brand lockup with tagline
    ("Premium food brand logo lockup. Large bold custom wordmark 'Olevia' in deep olive green (#2D4A22), heavy rounded letterforms with tight tracking. Below in small caps: 'PREMIUM FATS' in warm gold (#D4A017). Cream background (#FFF8E7). Clean centered composition. Sophisticated Mediterranean food branding. Professional brand identity.",
     "ayoh-olevia-6-lockup.png"),

    # 7. Label/badge format (like on packaging)
    ("Circular badge label logo for 'Olevia' premium food brand. Deep olive green circle background (#2D4A22) with white bold rounded custom wordmark 'Olevia' centered. Gold ring border (#D4A017). Premium quality seal aesthetic. Like an artisanal food label or packaging badge. Clean, bold, confident. Professional brand identity.",
     "ayoh-olevia-7-badge.png"),
    
    # 8. Glass bottle mockup context
    ("Premium olive oil style glass bottle with 'Olevia' brand label. Clean cream-colored label with bold olive green custom wordmark. Warm studio lighting on white background. Minimal elegant packaging. Mediterranean premium food brand. Product photography style. Professional brand identity mockup.",
     "ayoh-olevia-8-bottle.png"),
]

results = {}
for prompt, filename in prompts:
    result = generate(prompt, filename)
    results[filename] = result
    time.sleep(1)

success = sum(1 for v in results.values() if v)
print(f"\n{'='*40}")
print(f"Generated {success}/{len(results)} Olevia logos (Ayoh! DNA)")

with open(OUT / "results-ayoh.json", "w") as f:
    json.dump(results, f, indent=2)
