# Test de familias nuevas (nov-2026): pole, onsen, pregnant, threesome.
# Personajes validados: Mirko (bunny), Lauma (maid), Tsunade (mature).
# Estructura BREAK canónica. Threesome deliberadamente rompe 1girl+1boy.

import json
import pathlib
import sys

sys.path.insert(0, "Engine")
from api_client import ForgeClient

BASE = pathlib.Path(r"C:\Users\Usuario\Downloads\SD")
OUT = BASE / "Output" / "test_nuevas_familias"
OUT.mkdir(parents=True, exist_ok=True)

MASTER = """masterpiece, best quality, highly detailed, sharp focus, very aesthetic, very awa,
detailed background, score_9, score_8_up, <lora:IFL_v1.0_IL:0.7> <lora:add-detail-xl:0.5>
<lora:blackwhiplash(bwl)-guy90-Illust-Lorav3:0.6> blaash, <lora:scara2b_ill_v1.00:0.7> scara2b-style,
<lora:Add_color_ILXLv1:3>, 1girl, solo"""

NEG = ("lowres, bad anatomy, bad hands, extra fingers, missing fingers, extra limbs, missing limbs, "
       "fused fingers, poorly drawn face, poorly drawn hands, censored, mosaic censoring, bar censor, "
       "mirror, reflection")

MIRKO = "<lora:Mirko:0.8>, mirko, rabbit_ears, red_eyes, white_hair, very_long_hair, large_breasts, dark_skin, dark-skinned_female, mature_female, muscular_female, rabbit_tail"
LAUMA = "<lora:Lauma_ILv3.1:0.8> laumagenshin, hair intakes, pointy ears, long hair, hair over one eye, antlers, purple hair, bangs, hair ornament, large breasts, blue eyes, ear piercing, cleavage, bare shoulders, blue nails, nail polish"
TSUNADE = "<lora:Tsunade_illustrious_v1:0.8> Tsunade, tsunade_(naruto), 1girl, blonde_hair, large_breasts, brown_eyes, forehead_mark, facial_mark, mature_female"

TESTS = [
    ("pole_mirko", MIRKO, "playboy_bunny, white_leotard, strapless_leotard, fishnet_pantyhose, rabbit_tail",
     "pole_dancing, pole, spinning, sitting on pole, legs wrapped around pole, indoors, club, stage, night, from front"),
    ("onsen_lauma", LAUMA, "towel, naked_towel, half naked",
     "onsen, shared_bathing, mixed-sex_bathing, steam, sitting, water, legs submerged, outdoors, night, from front"),
    ("pregnant_tsunade", TSUNADE, "half naked",
     "pregnant, big_belly, hands on belly, sitting, indoors, window light, smile, from front"),
    ("threesome_mirko", MIRKO, "playboy_bunny, white_leotard, fishnet_pantyhose, half naked",
     "threesome, mmf_threesome, multiple_boys, 2boys, on_bed, lying, heterosexual, uncensored, from front"),
]

client = ForgeClient("http://127.0.0.1:7860")
assert client.check_status(), "Forge no responde"

manifest = []
for name, char_line, outfit, pose in TESTS:
    prompt = (f"{MASTER}\nBREAK\n1girl, {char_line}, {outfit}\n"
              f"BREAK\n{pose}")
    images, info = client.txt2img(prompt, negative_prompt=NEG, width=832, height=1216,
                                  steps=28, cfg_scale=6.0, seed=-1)
    for j, img in enumerate(images, 1):
        fname = f"{name}_{j:02d}.png"
        (OUT / fname).write_bytes(img)
        manifest.append({"file": fname, "test": name, "pose": pose, "prompt": prompt,
                         "seed": info.get("seed")})
        print(f"[OK] {fname} seed={info.get('seed')}")

(OUT / "manifest.json").write_text(json.dumps(manifest, ensure_ascii=False, indent=1), encoding="utf-8")
print(f"[OK] {OUT} ({len(manifest)} imgs)")
