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

dockaiq i2i-qwen-image-edit-lightning-4step (storyboard) 로 face_sheet 기반 변주 31장.

구성비: 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 {옷}' 토큰 강제

캐릭터: 17yo solo rapper (hip-hop / trap).
모티프: 블랙·레드·화이트 · 스트릿 · 오버사이즈 · 래퍼 무드.
주의: 17세 — 슬립드레스/딥넥 회피, 스트릿·스테이지·오버사이즈 위주.
"""
from __future__ import annotations
from pathlib import Path

FACE = Path.home() / "Documents/vault/chosn/people/CHAERIN/비주얼/얼굴설정1.png"
DATASET_DIR = Path.home() / "ai/experiments/chaerin-dataset-gen/dataset/cropped"
WORKFLOW = "i2i-qwen-image-edit-lightning-4step"
TRIGGER = "chaerin_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 167cm 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": "167cm 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 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 rapper posture, weight shifted onto one leg, shoulders dropped, caught mid-moment with cool 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."
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 slightly lifted — rapper presence, 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_white", "close-up", SIZE_PORTRAIT, EXPR_FIERCE,
     "Studio face portrait against a clean white seamless backdrop. Cool neutral key light from camera left. Long jet-black hair with subtle red highlights, slightly tousled. Bold matte black eyeliner, neutral lip. Direct eye contact with cool stare.",
     "studio portrait, white backdrop, cool neutral key, jet black hair red highlights, bold black eyeliner, neutral lip, direct cool stare"),
    ("closeup_02_threequarter_red", "close-up", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Three-quarter face angle turned slightly toward the lens. Hard red gel light from camera-right with deep shadow on the opposite side. A few hair strands fall across the cheek. Subtle black eyeshadow.",
     "three-quarter face, hard red gel light, deep shadow opposite side, hair across cheek, black eyeshadow"),
    ("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 pulled into a high tight pony with a few baby hairs. Black studio wall.",
     "side profile, hard rim light, high tight pony, baby hairs, black wall"),
    ("closeup_04_neon_lookup", "close-up", SIZE_PORTRAIT, EXPR_FIERCE,
     "Outdoor night street between concrete buildings. Red and white neon spill across the face from above. Slight chin lift, sharp upward gaze. Hair slightly tousled.",
     "neon street night, red white spill, chin lift, sharp upward gaze, 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 brick wall behind.",
     "candid mid-laugh, sun catchlight, shallow depth of field, brick wall background"),
    ("closeup_06_window_overcast", "close-up", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Cool overcast window light from a tall steel-frame window. Long hair frames the face. Faint closed-mouth smile. Soft slate gray industrial wall behind.",
     "overcast window light, steel frame window, hair framing face, faint smile, slate gray wall"),
    ("closeup_07_stage_red_wash", "close-up", SIZE_PORTRAIT, EXPR_FIERCE,
     "Live stage moment. Hard red wash light raking from camera right, white ambient fill. Sweat-glossed skin. Microphone barely visible at the bottom edge. Hoop earrings catch the light.",
     "live stage red wash, white ambient fill, sweat-glossed skin, mic edge, hoop 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_blacktank", "bust", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Clean white cyclorama studio. Fitted ribbed black tank top, sleeveless. Long hair loose. Soft frontal softbox lighting. Silver chain necklace.",
     "white cyclorama studio, wearing fitted ribbed black tank top sleeveless silver chain necklace, loose long hair, soft frontal softbox"),  # form-fit
    ("bust_02_studio_redcrop", "bust", SIZE_PORTRAIT, EXPR_FIERCE,
     "Studio with deep red backdrop. Fitted long-sleeve black crop top with mock neck. Warm tungsten side light. Silver hoop earrings.",
     "studio deep red backdrop, wearing fitted long-sleeve black crop top mock neck silver hoop earrings, warm tungsten side light"),  # form-fit
    ("bust_03_alley_meshlong", "bust", SIZE_PORTRAIT, EXPR_FIERCE,
     "Narrow Seoul back alley at night. Long-sleeve sheer black mesh top layered over a black sports bra, no jacket. Red-white neon rim light. Layered silver chains.",
     "seoul back alley night, wearing long-sleeve sheer black mesh top over black sports bra layered silver chains, red white neon rim"),  # form-fit
    ("bust_04_studio_oversizedtee", "bust", SIZE_PORTRAIT, EXPR_WARM,
     "Soft daylight studio. Oversized vintage white logo tee with washed graphic, slightly off the shoulder. Hands tucked into front pockets of denim shorts (not visible).",
     "daylight studio, wearing oversized vintage white logo tee slightly off shoulder, soft daylight"),  # casual mid
    ("bust_05_dressing_black_blazer", "bust", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Backstage dressing room. Hollywood mirror bulbs rim-light the silhouette. Oversized black structured blazer with shoulder pads, open over a fitted white tank, silver chain layers at the neck. One hand adjusting a silver hoop.",
     "backstage dressing room, hollywood mirror bulbs, wearing oversized black structured blazer shoulder pads open over fitted white tank silver chain layers, adjusting silver hoop"),  # outerwear
    ("bust_06_cafe_hoodie", "bust", SIZE_PORTRAIT, EXPR_WARM,
     "Cafe interior with warm tungsten pendants. Black oversized logo hoodie unzipped halfway over a fitted white ribbed tank. Resting forearms on a pale oak table. Iced americano blurred in foreground.",
     "cafe interior, warm tungsten pendants, wearing black oversized logo hoodie unzipped halfway over fitted white ribbed tank, oak table iced americano foreground"),  # casual mid (zip hoodie ≈ outerwear-light)
    ("bust_07_rooftop_corset", "bust", SIZE_PORTRAIT, EXPR_FIERCE,
     "Rooftop garden in afternoon. Black fitted corset top with thin straps over a white long-sleeve shirt underneath, structured neckline. Concrete planter foreground out of focus. Soft city skyline behind. Silver layered chains.",
     "rooftop afternoon, wearing black fitted corset top thin straps over white long-sleeve shirt structured neckline silver chains, concrete planter foreground, soft skyline"),  # form-fit (corset over base layer = covered)

    # ── Thigh-up × 6 (3 form-fit / 2 casual mid / 1 outerwear) ─
    ("thigh_01_street_skinny_redtee", "thigh-up", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Walking along a Seoul side street at dusk. Black skinny jeans and a fitted vintage red logo tee tucked in halfway. White chunky sneakers. Silver chain belt. Hands relaxed at sides.",
     "seoul side street dusk, wearing black skinny jeans fitted vintage red logo tee tucked, white chunky sneakers, silver chain belt"),  # form-fit
    ("thigh_02_stage_leather_set", "thigh-up", SIZE_PORTRAIT, EXPR_FIERCE,
     "Live stage under red and white wash lights. Black leather pants and a fitted cropped black tank with silver chain detail. Hand on a microphone stand blurred in foreground. Sweat sheen.",
     "stage red white wash, wearing black leather pants fitted cropped black tank silver chain detail, mic stand foreground, sweat sheen"),  # form-fit
    ("thigh_03_studio_redskirt", "thigh-up", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Editorial studio with white seamless backdrop. Structured high-waisted red leather mini skirt with a fitted black ribbed long-sleeve top tucked in. Black tights. Standing tall, hands at sides.",
     "editorial studio white backdrop, wearing high-waisted red leather mini skirt fitted black ribbed long-sleeve top tucked, black tights, hands at sides"),  # form-fit (skirt fitted)
    ("thigh_04_park_oversized_set", "thigh-up", SIZE_PORTRAIT, EXPR_WARM,
     "Park path in late afternoon. Oversized black logo hoodie hanging mid-thigh and ripped light-wash blue baggy jeans. Hands tucked into hoodie pocket. Black baseball cap turned backward.",
     "park path late afternoon, wearing oversized black logo hoodie ripped light-wash blue baggy jeans black baseball cap backward, hands in pocket"),  # casual mid
    ("thigh_05_studio_baggy_cargo", "thigh-up", SIZE_PORTRAIT, EXPR_COMPOSED,
     "Editorial studio with dark backdrop. Fitted white ribbed tank top tucked into wide-leg black cargo pants with side pockets. Silver chain belt visible. Black combat boots (off-frame).",
     "editorial studio dark backdrop, wearing fitted white ribbed tank top wide-leg black cargo pants silver chain belt, tucked"),  # casual mid (cargo wide-leg)
    ("thigh_06_alley_oversized_blazer", "thigh-up", SIZE_PORTRAIT, EXPR_FIERCE,
     "Brick alley near a music venue. Oversized black structured blazer with shoulder pads worn open over a fitted black tank, distressed black skinny jeans. Streetlight side lighting. Silver chain belt.",
     "brick alley music venue, wearing oversized black structured blazer shoulder pads open over fitted black tank distressed black skinny jeans silver chain belt, streetlight side"),  # outerwear

    # ── Full-body × 10 (5 form-fit / 3 casual mid / 2 outerwear) ──
    ("fullbody_01_studio_blackset", "full-body", SIZE_TALL, EXPR_COMPOSED,
     "Plain white seamless studio backdrop. Long-sleeve fitted black mock-neck top tucked into high-waisted black skinny jeans. White chunky sneakers. Arms relaxed at sides. Silver chain belt. Even softbox lighting head to toe.",
     "white seamless studio, wearing long-sleeve fitted black mock-neck top high-waisted black skinny jeans silver chain belt, white chunky sneakers, even softbox lighting"),  # form-fit
    ("fullbody_02_studio_redset", "full-body", SIZE_TALL, EXPR_FIERCE,
     "Editorial studio with deep red seamless backdrop. Fitted black long-sleeve crop top and high-waisted black bike shorts. White chunky sneakers. Mid-pose with one arm extended. Silver layered chains.",
     "editorial studio red backdrop, wearing fitted black long-sleeve crop top high-waisted black bike shorts silver layered chains, white chunky sneakers, mid-pose one arm extended"),  # form-fit
    ("fullbody_03_street_skinny_whitelogotee", "full-body", SIZE_TALL, EXPR_COMPOSED,
     "Wide pedestrian crosswalk in evening. Black skinny jeans and a fitted vintage white logo tee tucked in. White chunky sneakers. Silver chain belt. Hands hooked into belt loops. Caught mid-stride. Blurred traffic.",
     "pedestrian crosswalk evening, wearing black skinny jeans fitted vintage white logo tee tucked white chunky sneakers silver chain belt, mid-stride"),  # form-fit
    ("fullbody_04_stage_leather_full", "full-body", SIZE_TALL, EXPR_FIERCE,
     "Concert stage view from front-of-house. Black leather pants and a fitted cropped long-sleeve black top with mesh shoulders. Black combat boots. Microphone in hand. Stage lights flaring red and white behind.",
     "concert stage front view, wearing black leather pants fitted cropped long-sleeve black top mesh shoulders, black combat boots, microphone, stage light flares red white"),  # form-fit
    ("fullbody_05_studio_redleather_set", "full-body", SIZE_TALL, EXPR_FIERCE,
     "Editorial studio with white backdrop. Red leather long structured trench-style coat-dress mid-thigh, belted at waist, fitted, knee-high black leather boots. Long sleek hair. Silver chunky chain necklace.",
     "editorial studio white backdrop, wearing red leather structured trench-style coat-dress mid-thigh belted at waist fitted silver chunky chain necklace, knee-high black leather boots, sleek hair"),  # form-fit (belted, fitted)
    ("fullbody_06_street_oversized_set", "full-body", SIZE_TALL, EXPR_COMPOSED,
     "Crossing a city street in evening. Oversized black logo hoodie hanging mid-thigh, baggy ripped light-wash blue cargo jeans, chunky white sneakers. Black baseball cap turned backward. Caught mid-stride.",
     "city street evening, wearing oversized black logo hoodie ripped light-wash blue baggy cargo jeans chunky white sneakers black baseball cap backward, mid-stride"),  # casual mid
    ("fullbody_07_park_layered", "full-body", SIZE_TALL, EXPR_WARM,
     "Tree-lined park path mid-day. Oversized white tee tucked partially into baggy black wide-leg cargo pants. Chunky white sneakers. Black bucket hat. Iced americano in one hand. Dappled sunlight.",
     "park path mid-day, wearing oversized white tee tucked partially baggy black wide-leg cargo pants chunky white sneakers black bucket hat, iced americano, dappled sun"),  # casual mid
    ("fullbody_08_subway_baggy", "full-body", SIZE_TALL, EXPR_COMPOSED,
     "Empty subway platform in evening. Vintage washed-black logo crewneck sweatshirt tucked partially into wide-leg distressed gray cargo pants. Chunky black combat boots. Platform fluorescents casting horizontal shadows.",
     "subway platform evening, wearing vintage washed-black logo crewneck sweatshirt wide-leg distressed gray cargo pants, chunky black combat boots, fluorescent shadows"),  # casual mid
    ("fullbody_09_rooftop_blazer", "full-body", SIZE_TALL, EXPR_FIERCE,
     "Rooftop balcony at night with Seoul skyline behind. Oversized black structured blazer with shoulder pads open over a fitted black tank top and high-waisted black skinny jeans. Black chunky platform boots. Silver layered chains. City bokeh in background.",
     "rooftop night seoul skyline, wearing oversized black structured blazer shoulder pads open over fitted black tank high-waisted black skinny jeans silver layered chains, black chunky platform boots, city bokeh"),  # outerwear
    ("fullbody_10_garage_long_coat", "full-body", SIZE_TALL, EXPR_COMPOSED,
     "Studio garage with brick wall and recording equipment behind. Long oversized black wool coat reaching mid-calf, open over a fitted white ribbed tank and black wide-leg cargo pants. Black combat boots. Coat falling open showing full body silhouette.",
     "studio garage brick wall recording equipment, wearing long oversized black wool coat over fitted white ribbed tank black wide-leg cargo pants, black combat 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)}장")
