"""FikoYT NSFW Prompt Studio — kategori bazlı zengin yetişkin prompt derleyici.

Tüm seçimler opsiyoneldir ('yok' = katkı yok). Çocuk koruması negatifleri
her zaman zorunlu olarak eklenir. Çıkış: prompt, negative, nsfw_lora_hint.
"""

_YOK = "yok"


def _k(*pairs):
    """[('id|english prompt'), ...] → combo list + lookup dict."""
    secenekler = [_YOK]
    harita = {}
    for p in pairs:
        kid, eng = p.split("|", 1)
        secenekler.append(kid)
        harita[kid] = eng
    return secenekler, harita


SEVIYE_SEC, SEVIYE = _k(
    "ima|suggestive, teasing, implied nudity",
    "sansursuz_ust|topless, bare chest, uncensored",
    "ciplak|fully nude, naked, uncensored, detailed anatomy",
    "erotik|erotic nude, sensual explicit, uncensored",
    "explicit|explicit sexual content, uncensored, detailed",
)
FIGUR_SEC, FIGUR = _k(
    "kadin|1girl, solo woman",
    "erkek|1boy, solo man",
    "ciftt|couple, man and woman",
    "iki_kadin|two women together",
    "iki_erkek|two men together",
    "grup|group, multiple people",
    "olgun_kadin|mature woman, milf",
    "fit_kadin|fit athletic woman",
    "kivrimli|curvy voluptuous woman",
    "ince|slim petite woman",
)
GOGUS_SEC, GOGUS = _k(
    "kucuk|small breasts",
    "orta|medium breasts",
    "buyuk|large breasts",
    "cok_buyuk|huge breasts",
    "dogal|natural sagging breasts",
    "dik|perky breasts",
)
KIYAFET_SEC, KIYAFET = _k(
    "tam_giyinik|fully clothed, teasing",
    "yari_soyunmus|partially undressed, clothes half off",
    "soyunuyor|undressing, stripping",
    "ust_ciplak|topless, bottomless covered",
    "alt_ciplak|bottomless, top covered",
    "tamamen|completely nude",
    "islak_kiyafet|wet clothes, see-through",
    "yirtik|torn ripped clothes",
    "acik_gomlek|open shirt, unbuttoned",
)
IC_GIYIM_SEC, IC_GIYIM = _k(
    "dantel|lace lingerie",
    "siyah_dantel|black lace lingerie set",
    "kirmizi|red lingerie",
    "beyaz|white innocent lingerie",
    "deri|leather harness lingerie",
    "file|fishnet bodysuit",
    "babydoll|sheer babydoll nightie",
    "tanga|thong, g-string",
    "korse|corset, garter belt, stockings",
    "bikini|micro bikini",
)
POZ_SEC, POZ = _k(
    "ayakta|standing pose",
    "uzanmis|lying on bed",
    "yan_uzanmis|lying on side, sensual curve",
    "diz_ustu|kneeling pose",
    "dort_ayak|on all fours",
    "oturmus|sitting with legs crossed",
    "bacak_acik|legs spread",
    "egilmis|bending over",
    "duvara_yaslanmis|leaning against wall",
    "arkadan|from behind, looking back over shoulder",
    "kalca_vurgu|arched back, hips emphasized",
    "esnek|flexible pose, leg up",
)
AKSIYON_SEC, AKSIYON = _k(
    "poz_veriyor|posing seductively for camera",
    "dans|sensual dance, body rolling",
    "soyunma_dansi|striptease performance",
    "dokunuyor|touching own body sensually",
    "opusme|passionate kissing",
    "sarilma|intimate embrace, skin contact",
    "yatak_oyunu|intimate on bed together",
    "dus|showering, water on skin",
    "yag|oiled body, glistening skin",
    "masaj|sensual massage scene",
)
VUCUT_SEC, VUCUT = _k(
    "terli|sweaty glistening skin",
    "islak|wet body, water drops",
    "yagli|oiled shiny skin",
    "ten_detay|detailed skin texture, pores",
    "kalca|round detailed butt",
    "bacaklar|long toned legs",
    "karin|toned stomach, abs",
    "dovme|tattooed body",
    "piercing|body piercings",
    "cilek_ten|flushed aroused skin",
)
IFADE_SEC, IFADE = _k(
    "bastan_cikarici|seductive gaze, bedroom eyes",
    "utangan|shy blushing expression",
    "azgin|aroused expression, parted lips",
    "zevk|pleasure expression, eyes closed",
    "inleme|moaning open mouth",
    "kontrol|dominant confident look",
    "itaatkar|submissive look",
    "oyuncu|playful biting lip",
)
ORTAM_SEC, ORTAM = _k(
    "yatak_odasi|dim bedroom, silk sheets",
    "lux_otel|luxury hotel suite",
    "dus_banyo|steamy bathroom shower",
    "havuz|private pool at night",
    "plaj|secluded beach sunset",
    "ofis|after-hours office desk",
    "kulup|neon nightclub vip room",
    "sauna|steamy sauna",
    "atolye|artist studio, draped fabric",
    "dogada|secluded forest meadow",
)
KAMERA_SEC, KAMERA = _k(
    "tam_boy|full body shot",
    "yakin|close-up intimate framing",
    "bel_ustu|waist-up shot",
    "alttan|low angle shot",
    "ustten|high angle from above",
    "pov|POV perspective",
    "ayna|mirror reflection shot",
    "arka_acidan|shot from behind",
)
ISIK_SEC, ISIK = _k(
    "mum|candlelight, warm flicker",
    "neon|neon pink-blue lighting",
    "pencere|soft window light, shadows",
    "altin_saat|golden hour glow on skin",
    "dusuk|low-key dramatic lighting",
    "yumusak|soft diffused boudoir lighting",
)

_KALITE = ("masterpiece, best quality, ultra detailed, realistic skin, "
           "8k, professional photography")
_KORUMA_NEG = ("child, kid, teen, underage, loli, shota, young, "
               "deformed, bad anatomy, extra limbs, watermark, lowres")


class FikoYTNSFWPromptStudio:
    """Kategori seçimlerinden tam NSFW prompt + negatif + LoRA önerisi derler."""

    @classmethod
    def INPUT_TYPES(cls):
        return {
            "required": {
                "seviye": (SEVIYE_SEC, {"default": "ima"}),
                "figur": (FIGUR_SEC, {"default": "kadin"}),
                "gogus": (GOGUS_SEC,),
                "kiyafet_durumu": (KIYAFET_SEC,),
                "ic_giyim": (IC_GIYIM_SEC,),
                "poz": (POZ_SEC,),
                "aksiyon": (AKSIYON_SEC,),
                "vucut_detay": (VUCUT_SEC,),
                "ifade": (IFADE_SEC,),
                "ortam": (ORTAM_SEC,),
                "kamera": (KAMERA_SEC,),
                "isik": (ISIK_SEC,),
                "kalite_ekle": ("BOOLEAN", {"default": True}),
            },
            "optional": {
                "base_prompt": ("STRING", {"default": "", "multiline": True}),
                "ekstra": ("STRING", {"default": "", "multiline": True}),
                "negatif_ekstra": ("STRING", {"default": ""}),
            },
        }

    RETURN_TYPES = ("STRING", "STRING", "STRING")
    RETURN_NAMES = ("prompt", "negative", "nsfw_lora_hint")
    FUNCTION = "derle"
    CATEGORY = "FikoYT/nsfw"
    OUTPUT_NODE = True

    def derle(self, seviye, figur, gogus, kiyafet_durumu, ic_giyim, poz,
              aksiyon, vucut_detay, ifade, ortam, kamera, isik,
              kalite_ekle, base_prompt="", ekstra="", negatif_ekstra=""):
        parca = []
        if base_prompt.strip():
            parca.append(base_prompt.strip())
        for harita, kid in (
            (FIGUR, figur), (SEVIYE, seviye), (GOGUS, gogus),
            (KIYAFET, kiyafet_durumu), (IC_GIYIM, ic_giyim), (POZ, poz),
            (AKSIYON, aksiyon), (VUCUT, vucut_detay), (IFADE, ifade),
            (ORTAM, ortam), (KAMERA, kamera), (ISIK, isik),
        ):
            if kid != _YOK and kid in harita:
                parca.append(harita[kid])
        if ekstra.strip():
            parca.append(ekstra.strip())
        if kalite_ekle:
            parca.append(_KALITE)
        prompt = ", ".join(parca)

        neg = _KORUMA_NEG
        if negatif_ekstra.strip():
            neg = f"{neg}, {negatif_ekstra.strip()}"

        lora = ("NSFW_master_Flux.safetensors"
                if seviye in ("ciplak", "erotik", "explicit",
                              "sansursuz_ust") else "")
        return {"ui": {"text": [prompt]}, "result": (prompt, neg, lora)}


NODE_CLASS_MAPPINGS = {"FikoYTNSFWPromptStudio": FikoYTNSFWPromptStudio}
NODE_DISPLAY_NAME_MAPPINGS = {
    "FikoYTNSFWPromptStudio": "FikoYT 🔞 NSFW Prompt Studio",
}
