# Test de outfits calibrados (nov-2026): Mirko, Akeno, Mitsuki Bakugo.
# 3 personajes x 4 poses = 12 imgs, con estructura BREAK canonica.
# Uso: python Engine/_test_outfits.py

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_outfits_nov"
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"
AKENO = "himejima akeno, high school dxd, purple eyes, hair between eyes, black hair, very long hair, ponytail, hair ribbon, large breasts"
MITSUKI = "<lora:Mitsuki_Bakugo_My_Hero_Academia:0.85> m1tsuk1b&kug0, 1girl, mature female, solo, spiked hair, blonde hair, short hair, red eyes"

TESTS = [
    ("mirko_bunny", MIRKO,
     "playboy_bunny, white_leotard, strapless_leotard, white_shirt, fishnet_pantyhose, rabbit_tail, half naked",
     [
        "standing, hand on hip, weight on one leg, smiling, outdoors, beach, sea, day, three-quarter view",
        "sitting on edge, legs crossed, leaning forward, outdoors, beach bar, cocktail, smile, from front",
        "leaning against wall, one leg up, arms above head, teasing smile, indoors, bar, night, from side",
        "kneeling, sitting on heels, hands on thighs, looking up, indoors, bed, night, from front",
     ]),
    ("akeno_maid", AKENO,
     "maid, maid_apron, frilled_apron, frilled_skirt, white_apron, tiara, black_ribbon, high_heels, half naked",
     [
        "standing, hand on hip, weight on one leg, smiling, indoors, dining room, table, from front",
        "sitting on chair, legs over armrest, lazy confident pose, indoors, living room, sofa, from side",
        "leaning against table, arms on table, smiling, indoors, cafe, night, looking at viewer",
        "kneeling, holding tray, serving pose, indoors, kitchen counter, smile, from front",
     ]),
    ("mitsuki_gym", MITSUKI,
     "gym_uniform, white_shirt, collared_shirt, white_skirt, pencil_skirt, half naked",
     [
        "standing, hands behind head, arched back, confident expression, outdoors, park, day, three-quarter view",
        "sitting on bench, legs crossed, leaning back, arms behind head, outdoors, terrace, smile, from front",
        "leaning against wall, one leg up, arms crossed, teasing smile, outdoors, street, from side",
        "standing, holding bag, looking over shoulder, smiling, indoors, cafe, day, looking at viewer",
     ]),
]

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

manifest = []
for name, char_line, outfit, poses in TESTS:
    for i, pose in enumerate(poses, 1):
        if i % 2 == 0:  # variante spicy suave en poses 2 y 4
            prompt = (f"{MASTER}\nBREAK\n1girl, {char_line}, {outfit}\n"
                      f"BREAK\n1boy, (faceless male:1.4), muscular body, taller male\n"
                      f"BREAK\n{pose}, hetero, uncensored")
        else:
            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}_{i:02d}_{j}.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)")
