#!/usr/bin/env python3
"""RINA Qwen-Image-2512 LoRA v1 학습용 데이터셋 정의.

dockaiq i2i-qwen-image-edit-lightning-4step (storyboard) 로 face_sheet 기반 변주 31장.
musubi-tuner 요구 포맷(image.png + image.txt 쌍).

구성비: close-up 8 / bust 7 / thigh-up 6 / full-body 10 = 31

의상 다양성 (2026-04-27 monoculture 회피):
  full-body 10 = form-fitting 5 + casual mid 3 + outerwear 2
  caption 'wearing {옷}' 토큰 강제

캐릭터: 16yo girl crush dance K-pop solo (BLACKPINK/2NE1/MEOVV style).
모티프: 블랙·핑크·골드, 스트릿 럭셔리, 댄스복, 강렬한 메이크업.
주의: 16세 — 과도한 성인 노출/딱붙은 슬립드레스류 회피, 댄스복·스트릿 위주.
"""
from __future__ import annotations
from pathlib import Path

FACE = Path.home() / "Documents/vault/chosn/people/RINA/비주얼/얼굴시트.png"
DATASET_DIR = Path.home() / "ai/experiments/rina-dataset-gen/dataset/cropped"
WORKFLOW = "i2i-qwen-image-edit-lightning-4step"
TRIGGER = "rina_chosn"

BODY_ANATOMY = {
    "close-up": "",
    "bust": "Body: slim toned dancer build, broad but softly sculpted shoulders, long horizontal clavicles.",
    "thigh-up": "Body: lean dancer build, broad shoulders softly wider than hips, long horizontal clavicles, narrow waist, gently curved glutes from years of dance training.",
    "full-body": "Body: approximately 165cm tall, slim lean dancer build, broad but softly sculpted shoulders subtly wider than hips, long horizontal clavicles, narrow natural waist, gently curved glutes, slender long toned legs, 8-to-8.5 head proportion.",
}
BODY_CAPTION_TAIL = {
    "close-up": "",
    "bust": "slim dancer upper build, broad soft shoulders, long clavicles",
    "thigh-up": "lean dancer build, broad soft shoulders, narrow waist, gently curved glutes",
    "full-body": "165cm tall, slim lean dancer build, broad soft shoulders subtly wider than hips, long clavicles, narrow waist, gently curved glutes, slender long legs, 8-head proportion",
}
CAPTION_IDENTITY = f"{TRIGGER}, korean japanese woman"

SIZE_PORTRAIT = (1080, 1440)
SIZE_TALL = (1080, 1440)

FRAMING = {
    "close-up": "Extreme close-up of face and jawline only, cropped tightly above the collarbone, NO shoulders, NO clothing visible in frame. Face fills three-quarters of the frame, rule of thirds composition with eyes on the upper horizontal line.",
    "bust": "Bust shot from the mid-chest up, head in the upper third of the frame with gentle headroom, rule of thirds composition.",
    "thigh-up": "Three-quarter frame from mid-thigh up, head in the upper third, rule of thirds composition with generous vertical space.",
    "full-body": "Full body in frame head to toe with feet visible, wide framing, head in the upper third, rule of thirds composition.",
}

POSE_DEFAULT = "Confident relaxed dancer posture, weight shifted onto one leg, shoulders square, caught mid-moment with subtle attitude — not posed for a photo."

EXPR_WARM = "Gentle closed-mouth smile with a faint eye crinkle, relaxed gaze."
EXPR_COMPOSED = "Composed cool expression, relaxed mouth, sharp confident gaze — girl crush mood."
EXPR_LAUGH = "Candid unposed laugh caught mid-moment, eyes crinkled, teeth barely visible."
EXPR_FIERCE = "Sharp focused stare straight at the lens, lips slightly closed, chin lifted — runway/stage attitude, not aggressive."

# (stem, composition, size, expression, scene, caption_tail)
ITEMS: list[tuple[str, str, tuple[int, int], str, str, str]] = [
    # ── Close-up × 8 ─────────────────────────────────────────
    ("closeup_01_studio_glossy", "close-up", SIZE_PORTRAIT, EXPR_FIERCE,
     "Studio face portrait against a soft pink seamless backdrop. Cool key light from camera left. Long jet-black hair with subtle pink-tinted highlights, sleek and glossy. Bold winged eyeliner, glossy pink lip. Direct eye contact.",
     "studio portrait, soft pink backdrop, cool key light, jet black sleek hair pink highlights, winged eyeliner, glossy pink lip"),
    ("closeup_02_threequarter_warm", "close-up", SIZE_PORTRAIT, EXPR_WARM,
     "Three-quarter face angle turned slightly toward the lens. Warm golden key light from camera-right with soft amber bokeh. A few hair strands tucked behind one ear. Subtle shimmer eye makeup.",
     "three-quarter face, warm golden key, amber bokeh, hair tucked behind ear, shimmer eye makeup"),
    ("closeup_03_profile_rim", "close-up", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Clean side profile silhouette. Hard rim light from behind defines nose bridge and jawline. Hair gathered into a high sleek pony with a few baby hairs. Deep magenta studio wall.",
     "side profile, hard rim light, high sleek pony, baby hairs, deep magenta wall"),
    ("closeup_04_neon_lookup", "close-up", SIZE_PORTRAIT, EXPR_FIERCE,
     "Outdoor night street. Pink and gold neon spill across the face from above. Slight chin lift, sharp upward gaze. Hair slightly tousled by night breeze.",
     "neon street night, pink gold spill, chin lift, sharp upward gaze, breeze tousled hair"),
    ("closeup_05_candid_laugh", "close-up", SIZE_PORTRAIT, EXPR_LAUGH,
     "Caught mid-laugh, eyes crinkled. Natural sun catchlights. Shallow depth of field. Out-of-focus pastel pink wall behind.",
     "candid mid-laugh, sun catchlight, shallow depth of field, pastel pink wall background"),
    ("closeup_06_overcast_window", "close-up", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Cool overcast window light from a tall window. Long sleek black hair frames the face. Faint closed-mouth smile. Soft cream wall behind.",
     "overcast window light, sleek hair framing face, faint smile, cream wall"),
    ("closeup_07_stage_pink_wash", "close-up", SIZE_PORTRAIT, EXPR_FIERCE,
     "Live stage moment. Hot pink wash light from camera right, gold ambient fill. Sweat-glossed skin under the lights. Microphone barely visible at the bottom edge. Glittering earrings catch the light.",
     "live stage hot pink wash, gold ambient fill, sweat-glossed skin, mic edge, glittering earrings"),
    ("closeup_08_rooftop_skylook", "close-up", SIZE_PORTRAIT, EXPR_WARM,
     "Face tilted slightly upward toward an open sky. Soft late-afternoon top light. Faint smile. Concrete rooftop edge softly out of focus behind.",
     "face tilted up sky, late afternoon top light, faint smile, concrete rooftop background"),

    # ── Bust × 7 (4 form-fit / 2 casual mid / 1 outerwear) ───
    ("bust_01_studio_pinkbralette", "bust", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Clean white cyclorama studio. Fitted hot pink ribbed crop top with thin straps, exposed collarbones. Long sleek black hair loose. Soft frontal softbox lighting.",
     "white cyclorama studio, wearing fitted hot pink ribbed crop top thin straps, sleek loose hair, soft frontal softbox"),  # form-fit
    ("bust_02_dance_blacktank", "bust", SIZE_PORTRAIT, EXPR_FIERCE,
     "Mirrored dance studio with practice barre behind. Fitted black ribbed athletic tank top with deep neckline. Warm tungsten work-light from side. Gold hoop earrings.",
     "mirrored dance studio, practice barre, wearing fitted black ribbed athletic tank top deep neckline, warm tungsten side light, gold hoop earrings"),  # form-fit
    ("bust_03_alley_meshblack", "bust", SIZE_PORTRAIT, EXPR_FIERCE,
     "Narrow Seoul back alley at night. Long-sleeve sheer black mesh top layered over a black bandeau, no jacket. Pink-gold neon rim light. Bold chain necklace.",
     "seoul back alley night, wearing long-sleeve sheer black mesh top over black bandeau bold chain necklace, pink gold neon rim"),  # form-fit
    ("bust_04_studio_pinkflannel", "bust", SIZE_PORTRAIT, EXPR_WARM,
     "Soft daylight studio. Oversized pastel pink flannel shirt half-unbuttoned over a fitted white ribbed tank. Hands halfway tucked into front pockets.",
     "daylight studio, wearing oversized pastel pink flannel shirt half-unbuttoned over fitted white ribbed tank, hands in pockets"),  # casual mid
    ("bust_05_dressing_leather_jacket", "bust", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Backstage dressing room. Hollywood mirror bulbs rim-light the silhouette. Black cropped leather biker jacket open over a fitted black bralette top, gold chain layers at the neck. One hand adjusting a gold hoop earring.",
     "backstage dressing room, hollywood mirror bulbs, wearing black cropped leather biker jacket open over fitted black bralette gold chain layers, adjusting gold hoop"),  # outerwear
    ("bust_06_cafe_knit", "bust", SIZE_PORTRAIT, EXPR_WARM,
     "Cafe interior with warm tungsten pendants. Cream ribbed knit crop sweater with rolled-up sleeves. Resting forearms on a pale oak table. Steaming pink latte cup blurred in foreground.",
     "cafe interior, warm tungsten pendants, wearing cream ribbed knit crop sweater rolled sleeves, oak table pink latte foreground"),  # casual mid
    ("bust_07_rooftop_corset", "bust", SIZE_PORTRAIT, EXPR_FIERCE,
     "Rooftop garden in afternoon. Black satin corset top with thin straps, structured neckline. Concrete planter foreground out of focus. Soft city skyline behind. Gold layered necklaces.",
     "rooftop afternoon, wearing black satin corset top thin straps structured neckline gold layered necklaces, concrete planter foreground, soft skyline"),  # form-fit

    # ── Thigh-up × 6 (3 form-fit / 2 casual mid / 1 outerwear) ─
    ("thigh_01_street_bikershorts", "thigh-up", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Walking along a Seoul side street at dusk. Black biker shorts and a fitted hot pink ribbed crop top. White chunky sneakers. Gold belt chain. Hands relaxed at sides.",
     "seoul side street dusk, wearing black biker shorts fitted hot pink ribbed crop top, white chunky sneakers, gold belt chain"),  # form-fit
    ("thigh_02_stage_minidress", "thigh-up", SIZE_PORTRAIT, EXPR_FIERCE,
     "Live stage under pink and gold wash lights. Black sequined mini dress with structured shoulders, knee-length. Hand on a microphone stand blurred in foreground. Sweat sheen.",
     "stage pink gold wash, wearing black sequined mini dress structured shoulders knee-length, mic stand foreground, sweat sheen"),  # form-fit
    ("thigh_03_bar_crop_skirt", "thigh-up", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Seated on a tall stool at a luxury bar. Fitted black crop top and a structured high-waisted black mini skirt. One leg crossed. Empty champagne glass on the bar. Gold hoop earrings.",
     "luxury bar stool, wearing fitted black crop top structured high-waisted black mini skirt, one leg crossed, gold hoops"),  # form-fit
    ("thigh_04_park_oversized", "thigh-up", SIZE_PORTRAIT, EXPR_WARM,
     "Park path in late afternoon. Oversized white logo hoodie hanging mid-thigh and ripped light-wash blue baggy jeans. Hands tucked into hoodie pocket. Pink baseball cap.",
     "park path late afternoon, wearing oversized white logo hoodie ripped light-wash blue baggy jeans pink baseball cap, hands in pocket"),  # casual mid
    ("thigh_05_practice_cargo", "thigh-up", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Mirrored dance practice room. Fitted black sports bra top and high-waisted wide-leg black cargo pants with side pockets. White sneakers. Towel draped over shoulder.",
     "mirrored dance practice room, wearing fitted black sports bra top high-waisted wide-leg black cargo pants, white sneakers, towel on shoulder"),  # casual mid (cargo wide-leg)
    ("thigh_06_alley_leather_jacket", "thigh-up", SIZE_PORTRAIT, EXPR_FIERCE,
     "Brick alley near a club. Black cropped leather biker jacket open over a fitted pink crop top, distressed black skinny jeans. Streetlight side lighting. Gold chain belt.",
     "brick alley club, wearing black cropped leather biker jacket open over fitted pink crop top distressed black skinny jeans gold chain belt, streetlight side"),  # outerwear

    # ── Full-body × 10 (5 form-fit / 3 casual mid / 2 outerwear) ──
    ("fullbody_01_studio_dancewear", "full-body", SIZE_TALL, EXPR_COMPOSED,
     "Plain white seamless studio backdrop. Long-sleeve fitted black athletic crop top and high-waisted black biker shorts. White sneakers. Arms relaxed at sides. Even softbox lighting head to toe.",
     "white seamless studio, wearing long-sleeve fitted black athletic crop top high-waisted black biker shorts, white sneakers, even softbox lighting"),  # form-fit
    ("fullbody_02_practice_legs", "full-body", SIZE_TALL, EXPR_COMPOSED,
     "Mirrored dance practice room with wooden floor. Fitted black sports bra crop top and high-waisted shiny black athletic leggings with mesh side panels. White chunky sneakers. Mid-warmup with one arm extended overhead. Floor-to-ceiling windows behind.",
     "mirrored dance practice, wearing fitted black sports bra crop top high-waisted shiny black athletic leggings mesh side panels, white chunky sneakers, warmup pose"),  # form-fit
    ("fullbody_03_street_skinny_pinkcrop", "full-body", SIZE_TALL, EXPR_COMPOSED,
     "Wide pedestrian crosswalk in evening. Black skinny jeans and a fitted hot pink ribbed crop top tucked in. White chunky sneakers. Gold chain belt. Hands hooked into belt loops. Caught mid-stride. Blurred traffic.",
     "pedestrian crosswalk evening, wearing black skinny jeans fitted hot pink ribbed crop top tucked, white chunky sneakers, gold chain belt, mid-stride"),  # form-fit
    ("fullbody_04_stage_glitter_set", "full-body", SIZE_TALL, EXPR_FIERCE,
     "Concert stage view from front-of-house. Black glittering two-piece stage outfit — fitted bralette top with structured shoulders + matching high-waisted mini skirt. Black ankle boots with low heels. Microphone in hand. Stage lights flaring behind.",
     "concert stage front view, wearing black glittering two-piece stage outfit fitted bralette structured shoulders high-waisted mini skirt, black ankle boots, microphone, stage light flares"),  # form-fit
    ("fullbody_05_studio_pink_minidress", "full-body", SIZE_TALL, EXPR_FIERCE,
     "Editorial studio with hot pink backdrop. Hot pink mini bodycon dress with structured shoulders, knee-length, long sleeves. Black chunky platform boots. Long sleek hair over one shoulder. Gold layered necklaces.",
     "editorial studio hot pink backdrop, wearing hot pink mini bodycon dress structured shoulders knee-length long sleeves gold layered necklaces, black chunky platform boots, sleek hair"),  # form-fit
    ("fullbody_06_street_oversized_set", "full-body", SIZE_TALL, EXPR_COMPOSED,
     "Crossing a city street in evening. Oversized white logo hoodie hanging mid-thigh, baggy ripped light-wash blue cargo jeans, chunky white sneakers. Pink baseball cap turned backward. Caught mid-stride.",
     "city street evening, wearing oversized white logo hoodie ripped light-wash blue baggy cargo jeans chunky white sneakers pink baseball cap backward, mid-stride"),  # casual mid
    ("fullbody_07_park_layered", "full-body", SIZE_TALL, EXPR_WARM,
     "Tree-lined park path mid-day. Pastel pink oversized button-up shirt half-tucked into baggy cream wide-leg trousers. Off-white chunky loafers. Canvas tote bag in one hand. Dappled sunlight.",
     "park path mid-day, wearing pastel pink oversized button-up shirt half-tucked baggy cream wide-leg trousers, off-white chunky loafers, canvas tote, dappled sun"),  # casual mid
    ("fullbody_08_subway_baggy", "full-body", SIZE_TALL, EXPR_COMPOSED,
     "Empty subway platform in evening. Vintage black logo crewneck sweatshirt tucked partially into wide-leg distressed gray cargo pants. Chunky black combat boots. Platform fluorescents casting shadows.",
     "subway platform evening, wearing vintage black logo crewneck sweatshirt wide-leg distressed gray cargo pants, chunky black combat boots, fluorescent shadows"),  # casual mid
    ("fullbody_09_rooftop_leather_set", "full-body", SIZE_TALL, EXPR_FIERCE,
     "Rooftop balcony at night with Seoul skyline behind. Black cropped leather biker jacket open over a fitted black corset top and high-waisted black skinny jeans. Black chunky platform boots. Gold chain belt. City bokeh in background.",
     "rooftop night seoul skyline, wearing black cropped leather biker jacket fitted black corset top high-waisted black skinny jeans gold chain belt, black chunky platform boots, city bokeh"),  # outerwear
    ("fullbody_10_runway_long_coat", "full-body", SIZE_TALL, EXPR_COMPOSED,
     "Backstage runway corridor with mirrored walls. Long oversized blush pink wool coat reaching mid-calf, open over a fitted black ribbed bodysuit and black biker shorts. Black ankle boots. Coat falling open showing full body silhouette.",
     "backstage runway corridor mirrored walls, wearing long oversized blush pink wool coat over fitted black ribbed bodysuit black biker shorts, black ankle boots, coat open"),  # outerwear
]


def build_prompt(composition: str, expr: str, scene: str) -> str:
    framing = FRAMING[composition]
    body = BODY_ANATOMY[composition]
    parts = [
        "Keep the exact face, hair, and identity from the reference image.",
        framing,
    ]
    if body:
        parts.append(body)
    parts += [
        POSE_DEFAULT,
        expr,
        f"Scene: {scene}",
        "Photorealistic, natural color, subtle filmic grain, 35mm lens feel.",
    ]
    return " ".join(parts)


def build_caption(composition: str, tail: str) -> str:
    body_tail = BODY_CAPTION_TAIL[composition]
    segments = [CAPTION_IDENTITY]
    if body_tail:
        segments.append(body_tail)
    segments += [composition, tail]
    return ", ".join(segments)


if __name__ == "__main__":
    import argparse
    p = argparse.ArgumentParser()
    p.add_argument("--dry-run", action="store_true")
    args = p.parse_args()
    if args.dry_run:
        for stem, comp, size, expr, scene, tail in ITEMS:
            print(f"\n=== {stem} ({comp}) ===")
            print(f"  PROMPT: {build_prompt(comp, expr, scene)}")
            print(f"  CAPTION: {build_caption(comp, tail)}")
        print(f"\n총 {len(ITEMS)}장")
