"""Expert Transformation Agent prompts module - Bilingual support"""

from typing import List, Optional
from .language_config import LanguageType


def get_expert_generation_prompt(
    query: str,
    categories: List[str],
    expert_count: int,
    custom_experts: Optional[List[str]] = None,
    lang: LanguageType = "zh"
) -> str:
    """Step 0: Generate expert team (not dependent on topic, purely random and diverse)"""
    import time
    import random

    # Add timestamp and random number for diversity
    seed = int(time.time() * 1000) % 10000

    if lang == "en":
        custom_text = ""
        if custom_experts and len(custom_experts) > 0:
            custom_text = f" (Specified: {', '.join(custom_experts[:expert_count])})"

        diversity_hints = [
            "obscure, non-mainstream, cross-disciplinary",
            "rare occupations, emerging fields, fringe disciplines",
            "unconventional, innovative, niche specialties",
            "future-oriented, experimental, non-traditional",
            "cross-cultural, hybrid fields, unique perspectives"
        ]
        hint = random.choice(diversity_hints)

        return f"""/no_think
Randomly assemble a team of {expert_count} experts from completely different fields{custom_text}.

[Innovation Requirements] (Random seed: {seed})
- Prioritize {hint} experts
- Avoid common professions (such as doctors, engineers, teachers, lawyers, etc.)
- Each expert must be from a completely unrelated field
- The rarer and more innovative, the better

Return JSON:
{{"experts": [{{"id": "expert-0", "name": "profession", "domain": "field", "perspective": "viewpoint"}}, ...]}}

Rules:
- id should be expert-0 to expert-{expert_count - 1}
- name is the profession name (not a person's name), 2-5 words
- domain should be specific and unique, no duplicate types"""
    else:
        custom_text = ""
        if custom_experts and len(custom_experts) > 0:
            custom_text = f"（已指定：{', '.join(custom_experts[:expert_count])}）"

        diversity_hints = [
            "冷門、非主流、跨領域",
            "罕見職業、新興領域、邊緣學科",
            "非傳統、創新、小眾專業",
            "未來趨向、實驗性、非常規",
            "跨文化、混合領域、獨特視角"
        ]
        hint = random.choice(diversity_hints)

        return f"""/no_think
隨機組建 {expert_count} 個來自完全不同領域的專家團隊{custom_text}。

【創新要求】（隨機種子:{seed}）
- 優先選擇{hint}的專家
- 避免常見職業（如醫生、工程師、教師、律師等）
- 每個專家必須來自完全不相關的領域
- 越罕見、越創新越好

回傳 JSON：
{{"experts": [{{"id": "expert-0", "name": "職業", "domain": "領域", "perspective": "角度"}}, ...]}}

規則：
- id 為 expert-0 到 expert-{expert_count - 1}
- name 填寫職業名稱（非人名），2-5字
- domain 要具體且獨特，不可重複類型"""


def get_expert_keyword_generation_prompt(
    category: str,
    attribute: str,
    experts: List[dict],  # List[ExpertProfile]
    keywords_per_expert: int = 1,
    lang: LanguageType = "zh"
) -> str:
    """Step 1: Expert perspective keyword generation"""
    # Build expert list in clearer format
    experts_list = "\n".join([f"- {exp['id']}: {exp['name']}" for exp in experts])

    if lang == "en":
        return f"""/no_think
You need to play the role of the following experts to generate innovative keywords for an attribute:

[Expert List]
{experts_list}

[Task]
Attribute: "{attribute}" (Category: {category})

For each expert, please:
1. First understand the professional background, knowledge domain, and work content of that profession
2. Think about "{attribute}" from that profession's unique perspective
3. Generate {keywords_per_expert} innovative keyword(s) related to that specialty (2-6 words)

Keywords must reflect that expert's professional thinking style, for example:
- Accountant viewing "movement" → "cash flow", "cost-benefit"
- Architect viewing "movement" → "circulation design", "spatial flow"
- Psychologist viewing "movement" → "behavioral motivation", "emotional transition"

Return JSON:
{{"keywords": [{{"keyword": "term", "expert_id": "expert-X", "expert_name": "name"}}, ...]}}

Total of {len(experts) * keywords_per_expert} keywords needed, each keyword must be clearly related to the corresponding expert's professional field."""
    else:
        return f"""/no_think
你需要扮演以下專家，為屬性生成創新關鍵字：

【專家名單】
{experts_list}

【任務】
屬性：「{attribute}」（類別：{category}）

請為每位專家：
1. 先理解該職業的專業背景、知識領域、工作內容
2. 從該職業的獨特視角思考「{attribute}」
3. 生成 {keywords_per_expert} 個與該專業相關的創新關鍵字（2-6字）

關鍵字必須反映該專家的專業思維方式，例如：
- 會計師 看「移動」→「資金流動」「成本效益」
- 建築師 看「移動」→「動線設計」「空間流動」
- 心理師 看「移動」→「行為動機」「情緒轉變」

回傳 JSON：
{{"keywords": [{{"keyword": "詞彙", "expert_id": "expert-X", "expert_name": "名稱"}}, ...]}}

共需 {len(experts) * keywords_per_expert} 個關鍵字，每個關鍵字必須明顯與對應專家的專業領域相關。"""


def get_single_description_prompt(
    query: str,
    keyword: str,
    expert_id: str,
    expert_name: str,
    expert_domain: str,
    lang: LanguageType = "zh"
) -> str:
    """Step 2: Generate description for a single keyword"""
    if lang == "en":
        # If domain is generic, just use profession name
        domain_text = f" ({expert_domain} field)" if expert_domain and expert_domain != "Professional Field" else ""

        return f"""/no_think
You are a {expert_name}{domain_text}.

Task: Generate an innovative application description for "{query}".
Keyword: {keyword}

From your professional perspective, explain how to apply the concept of "{keyword}" to "{query}". The description should be specific, creative, 15-30 words.

Return JSON only, no other text:
{{"description": "your innovative application description"}}"""
    else:
        # 如果 domain 是通用的，就只用職業名稱
        domain_text = f"（{expert_domain}領域）" if expert_domain and expert_domain != "Professional Field" else ""

        return f"""/no_think
你是一位{expert_name}{domain_text}。

任務：為「{query}」生成一段創新應用描述。
關鍵字：{keyword}

從你的專業視角，說明如何將「{keyword}」的概念應用到「{query}」上。描述要具體、有創意，15-30字。

只回傳 JSON，不要其他文字：
{{"description": "你的創新應用描述"}}"""
