"use strict";
/**
 * Prompt Safety Module
 *
 * Google Generative AI policy-safe prompt kuralları.
 * nano-banana-2 ile üretilen görsellerin policy violation almaması için
 * prompt'ları otomatik olarak sanitize eder.
 *
 * Bu kurallar gerçek test sonuçlarından öğrenilmiştir:
 *
 * GEÇEN PATTERN'LER (safe):
 *   - "sports bra + leggings/yoga pants"
 *   - "bodycon mini dress"
 *   - "crop top + high-waisted shorts/jeans"
 *   - "one-piece swimsuit" (tek parça mayo)
 *   - "athletic jumpsuit / bodysuit"
 *   - "oversized sweater/hoodie off shoulder + shorts"
 *   - "leather jacket + corset top"
 *   - "fitted mini dress + strappy heels"
 *   - "swim shorts + crop top" (havuz kenarı)
 *
 * TAKILAN PATTERN'LER (policy violation):
 *   - "bikini string", "thong", "g-string"
 *   - "fishnet", "mesh", "see-through", "transparent", "sheer"
 *   - "clinging wet white t-shirt" (ıslak beyaz = see-through)
 *   - "barely covering", "riding up", "pulled down"
 *   - "slip dress + lace + bedroom" (lingerie algılanıyor)
 *   - "bare legs + morning after" kombinasyonu
 *   - "bra top" tek başına (sports bra OK, satin bra FAIL)
 *   - "deep plunge + visible cleavage" açık tanım
 *   - "underwear", "panties", "thong visible"
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SAFE_OUTFIT_OPTIONS = void 0;
exports.sanitizePrompt = sanitizePrompt;
exports.checkPromptSafety = checkPromptSafety;
const logger_js_1 = require("../../utils/logger.js");
const log = (0, logger_js_1.createModuleLogger)('prompt-safety');
/** Prompt'ta policy violation tetikleyen kelimeler */
const BANNED_WORDS = [
    // Doğrudan yasaklı kıyafet terimleri
    { pattern: /\bstring bikini\b/gi, replacement: 'fitted swimwear', reason: 'string bikini → fitted swimwear' },
    { pattern: /\bthong\b/gi, replacement: 'fitted bottoms', reason: 'thong → fitted bottoms' },
    { pattern: /\bg-string\b/gi, replacement: 'fitted bottoms', reason: 'g-string → fitted bottoms' },
    { pattern: /\bfishnet\b/gi, replacement: 'patterned', reason: 'fishnet → patterned' },
    { pattern: /\bsee-through\b/gi, replacement: 'form-fitting', reason: 'see-through → form-fitting' },
    { pattern: /\btransparent\b/gi, replacement: 'lightweight', reason: 'transparent → lightweight' },
    { pattern: /\bsheer\b/gi, replacement: 'delicate', reason: 'sheer → delicate' },
    { pattern: /\bmesh\b/gi, replacement: 'textured', reason: 'mesh → textured' },
    { pattern: /\bunderwear\b/gi, replacement: 'loungewear', reason: 'underwear → loungewear' },
    { pattern: /\bpanties\b/gi, replacement: 'shorts', reason: 'panties → shorts' },
    // lingerie genel tanımda çalışıyor, detaylı anatomik tanımlar sorun
    // { pattern: /\blingerie\b/gi, replacement: 'sleepwear', reason: 'lingerie → sleepwear' },
    { pattern: /\bunderwire\s+balconette\b/gi, replacement: 'structured lace', reason: 'underwire balconette → structured lace' },
    { pattern: /\bgarter\s+clips?\s+hanging/gi, replacement: 'decorative straps', reason: 'garter clips hanging → decorative straps' },
    { pattern: /\bscalloped\s+waistband\b/gi, replacement: 'lace trim', reason: 'scalloped waistband → lace trim' },
    { pattern: /\bnude\b/gi, replacement: 'neutral-toned', reason: 'nude → neutral-toned' },
    { pattern: /\bnaked\b/gi, replacement: 'minimal clothing', reason: 'naked → minimal clothing' },
    { pattern: /\btopless\b/gi, replacement: 'backless top', reason: 'topless → backless top' },
    // Tehlikeli tanımlayıcılar
    { pattern: /\bbarely covering\b/gi, replacement: 'form-fitting', reason: 'barely covering → form-fitting' },
    { pattern: /\briding up\b/gi, replacement: 'fitted', reason: 'riding up → fitted' },
    { pattern: /\bpulled down\b/gi, replacement: 'low-rise', reason: 'pulled down → low-rise' },
    { pattern: /\bvisible cleavage\b/gi, replacement: 'flattering neckline', reason: 'visible cleavage → flattering neckline' },
    { pattern: /\bdeep plunge\b/gi, replacement: 'low neckline', reason: 'deep plunge → low neckline' },
    { pattern: /\bexposing\b/gi, replacement: 'showing', reason: 'exposing → showing' },
    { pattern: /\bbare\s+(legs|thighs|skin|body|chest|midriff)\b/gi, replacement: 'toned $1', reason: 'bare X → toned X' },
    // Islak + beyaz kombinasyonu (see-through ima)
    { pattern: /\bclinging\s+wet\b/gi, replacement: 'damp', reason: 'clinging wet → damp' },
    { pattern: /\bcompletely\s+drenched\b/gi, replacement: 'rain-splashed', reason: 'completely drenched → rain-splashed' },
    // Satin/silk + bedroom = lingerie algısı
    { pattern: /\bsatin\s+bra\b/gi, replacement: 'satin halter top', reason: 'satin bra → satin halter top' },
    { pattern: /\bbra\s+top\b/gi, replacement: 'halter top', reason: 'bra top → halter top' },
    { pattern: /\bslip\s+dress\b/gi, replacement: 'mini dress', reason: 'slip dress → mini dress' },
    // KIE NSFW filter triggers
    { pattern: /\bbedroom\s+eyes\b/gi, replacement: 'intense confident gaze', reason: 'bedroom eyes → intense confident gaze' },
    { pattern: /\bseductive\b/gi, replacement: 'alluring', reason: 'seductive → alluring' },
    { pattern: /\bbiting\s+lip\b/gi, replacement: 'slight smirk', reason: 'biting lip → slight smirk' },
    { pattern: /\bintimate\s+(atmosphere|setting|vibe|mood)\b/gi, replacement: 'cozy $1', reason: 'intimate atmosphere → cozy atmosphere' },
    { pattern: /\bsensual\b/gi, replacement: 'elegant', reason: 'sensual → elegant' },
    { pattern: /\berotic\b/gi, replacement: 'glamorous', reason: 'erotic → glamorous' },
    { pattern: /\bprovocative\b/gi, replacement: 'bold', reason: 'provocative → bold' },
    { pattern: /\bsuggestive\b/gi, replacement: 'confident', reason: 'suggestive → confident' },
    { pattern: /\bboudoir\b/gi, replacement: 'glamour portrait', reason: 'boudoir → glamour portrait' },
];
/** Tehlikeli kelime kombinasyonları (tek başına OK ama birlikte FAIL) */
const DANGEROUS_COMBOS = [
    { words: ['wet', 'white', 'shirt'], warning: 'Wet white shirt = see-through algısı. Rengi değiştirin veya wet kaldırın.' },
    { words: ['lace', 'bedroom', 'bed'], warning: 'Lace + bedroom = lingerie algısı. Ortamı değiştirin.' },
    { words: ['silk', 'slip', 'bed'], warning: 'Silk slip + bed = lingerie algısı.' },
    { words: ['morning', 'after', 'bare'], warning: 'Morning after + bare = çok intimate.' },
    { words: ['bikini', 'string', 'minimal'], warning: 'Bikini string minimal = policy fail.' },
];
/**
 * Prompt'u Google policy-safe hale getirir.
 * Yasaklı kelimeleri güvenli alternatiflerle değiştirir.
 */
function sanitizePrompt(prompt) {
    let sanitized = prompt;
    const changes = [];
    const warnings = [];
    // 1. Yasaklı kelimeleri değiştir
    for (const rule of BANNED_WORDS) {
        rule.pattern.lastIndex = 0; // Reset regex state
        if (rule.pattern.test(sanitized)) {
            rule.pattern.lastIndex = 0; // Reset again before replace
            sanitized = sanitized.replace(rule.pattern, rule.replacement);
            changes.push(rule.reason);
        }
    }
    // 2. Tehlikeli kombinasyonları kontrol et
    const lowerPrompt = sanitized.toLowerCase();
    for (const combo of DANGEROUS_COMBOS) {
        const allPresent = combo.words.every(w => lowerPrompt.includes(w));
        if (allPresent) {
            warnings.push(combo.warning);
        }
    }
    const wasModified = changes.length > 0;
    if (wasModified) {
        log.info({ changeCount: changes.length, changes }, 'Prompt sanitized for policy compliance');
    }
    if (warnings.length > 0) {
        log.warn({ warnings }, 'Prompt contains potentially dangerous word combinations');
    }
    return {
        sanitizedPrompt: sanitized,
        originalPrompt: prompt,
        changes,
        warnings,
        wasModified,
    };
}
/**
 * Prompt'un policy-safe olup olmadığını kontrol eder (değiştirmeden).
 */
function checkPromptSafety(prompt) {
    const issues = [];
    const lower = prompt.toLowerCase();
    for (const rule of BANNED_WORDS) {
        rule.pattern.lastIndex = 0;
        if (rule.pattern.test(prompt)) {
            issues.push(rule.reason);
        }
    }
    for (const combo of DANGEROUS_COMBOS) {
        if (combo.words.every(w => lower.includes(w))) {
            issues.push(combo.warning);
        }
    }
    return { safe: issues.length === 0, issues };
}
/**
 * Policy-safe kıyafet önerileri.
 * Prompt oluştururken kullanılabilecek güvenli kıyafet seçenekleri.
 */
exports.SAFE_OUTFIT_OPTIONS = {
    sexy_casual: [
        'black sports bra and matching high-waisted compression leggings',
        'fitted black bodycon mini dress with spaghetti straps',
        'oversized knit sweater hanging off one shoulder with tiny cotton shorts',
        'tight cropped tank top showing midriff and high-waisted denim shorts',
        'fitted athletic jumpsuit with open back',
    ],
    nightlife: [
        'black velvet mini dress with sweetheart neckline and strappy heels',
        'fitted black leather jacket unzipped over structured corset top with dark jeans',
        'satin camisole top tucked into high-waisted leather mini skirt',
        'off-shoulder bodycon dress with gold accessories',
        'black halter neck jumpsuit with plunging neckline',
    ],
    swimwear: [
        'sleek black one-piece swimsuit with deep scoop neckline and cross-back straps',
        'dark navy athletic crop top and matching high-waisted swim shorts',
        'white one-piece swimsuit with side cutouts',
        'sporty two-piece with high-waisted bottoms and racerback top',
        'elegant dark one-piece with thin straps and open back',
    ],
    intimate_morning: [
        'oversized cream knit sweater off one shoulder with cotton shorts',
        'oversized mens button-down shirt loosely buttoned with top buttons open',
        'soft oversized hoodie reaching mid-thigh',
        'cozy knit cardigan worn open over fitted tank and sleep shorts',
        'large vintage band t-shirt as a dress',
    ],
    fashion_editorial: [
        'tailored blazer worn over delicate bralette with high-waisted trousers',
        'sheer blouse layered over fitted camisole with pencil skirt',
        'cropped leather jacket over fitted mini dress',
        'structured corset top paired with wide-leg trousers',
        'backless halter top with flowing palazzo pants',
    ],
};
//# sourceMappingURL=prompt-safety.js.map