import os
from pathlib import Path

ROOT = Path(r"C:\Users\Usuario\Downloads\SD")
BASE = ROOT / "_sandbox_cl_tagger" / "Momo Ayase 102"
HARVEST = BASE / "harvest" / "por_imagen.txt"
OUT = ROOT / "Output" / "test_momo_cosplay6"
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")
CHAR = "<lora:ayase_momo-koto-Illustrious v01:0.8> ayasemomo, hair between eyes, crossed bangs, green earrings, brown hair, red eyes, short hair, half naked"
COSPLAY = "cosplay, bat_print, pantyhose, jewelry, earrings, black_choker, leotard, animal_print, print_pantyhose, choker, purple_pantyhose, bare_shoulders, covered_navel, sky, black_leotard, clothing_cutout"
NEG = ("lowres, bad anatomy, bad hands, error, missing fingers, extra digit, fewer digits, cropped, worst quality, "
       "low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name, bad feet, "
       "multiple views, splits, 2girls, extra people, duplicate_character, cloned_character, similar_character, "
       "ugly, deformed, disfigured, mutation, mutated, extra_limbs, extra_arms, extra_legs, fused_fingers, "
       "long_neck, cross-eyed, censored, mosaic censoring, bar censor, mirror, reflection, mirrored, glass_reflection, "
       "reflective_surface")

cams = ["pov", "ass_focus", "from_behind", "cowboy_shot", "full_moon", "from_below"]

# Parse harvest
entries = []
lines = HARVEST.read_text(encoding="utf-8").splitlines()
i = 0
while i < len(lines):
    if ".txt" in lines[i] and not lines[i].startswith("#"):
        img = lines[i].split()[0]
        tags = lines[i+1].strip() if i+1 < len(lines) else ""
        entries.append((img, tags))
        i += 2
    else:
        i += 1

sel = entries[:20]

out_lines = []
out_lines.append("=" * 80)
out_lines.append("DRY-RUN: 20 prompts para Momo Ayase (cosplay vampiro/Morrigan)")
out_lines.append("Estructura: MASTER BREAK char, half naked BREAK cosplay (reducido) BREAK pose+entorno+cam")
out_lines.append("Seed: aleatoria (-1) en generacion real")
out_lines.append("=" * 80)
out_lines.append("")
out_lines.append("NEGATIVE PROMPT (comun a todos):")
out_lines.append(NEG)
out_lines.append("")
out_lines.append("=" * 80)

for idx, (img, tags) in enumerate(sel, 1):
    cam = cams[(idx-1) % len(cams)]
    pose_block = tags + ", " + cam
    prompt = f"{MASTER} BREAK {CHAR} BREAK {COSPLAY} BREAK {pose_block}"
    out_lines.append(f"--- [{idx}/20] {img} (cam: {cam}) ---")
    out_lines.append(prompt)
    out_lines.append("")

out_path = OUT / "dry_run_prompts.txt"
out_path.write_text("\n".join(out_lines), encoding="utf-8")
print(f"Escrito: {out_path}")
print(f"Total prompts: {len(sel)}")