"""Persona-driven prompt templates for Gateway AI capabilities."""

from enum import Enum
from string import Template


class Persona(str, Enum):
    """AI interviewer personas from the SOW."""

    TECHNICAL = "technical"
    HR_BEHAVIORAL = "hr_behavioral"
    FRIENDLY_COACH = "friendly_coach"
    EXECUTIVE = "executive"
    SALES = "sales"
    HEALTHCARE = "healthcare"
    FINANCE = "finance"
    CUSTOM = "custom"


PERSONA_DESCRIPTIONS: dict[Persona, str] = {
    Persona.TECHNICAL: (
        "Technical interviewer focused on skills, system design, coding rigor, "
        "and hands-on problem solving."
    ),
    Persona.HR_BEHAVIORAL: (
        "HR / behavioral interviewer using STAR-style probes for values fit, "
        "communication, collaboration, and past performance."
    ),
    Persona.FRIENDLY_COACH: (
        "Supportive coach persona for mock interviews — encouraging tone with "
        "constructive depth and clear feedback cues."
    ),
    Persona.EXECUTIVE: (
        "Executive leadership panel focused on strategy, stakeholder management, "
        "decision quality, and business impact."
    ),
    Persona.SALES: (
        "Sales & customer-success interviewer focused on persuasion, objection "
        "handling, pipeline thinking, and customer empathy."
    ),
    Persona.HEALTHCARE: (
        "Healthcare & clinical interviewer focused on patient safety, clinical "
        "judgment, compliance, and role-specific protocols."
    ),
    Persona.FINANCE: (
        "Finance & consulting interviewer focused on analytical rigor, case "
        "structuring, risk awareness, and stakeholder communication."
    ),
    Persona.CUSTOM: (
        "Custom company persona — style, depth, and evaluation criteria follow "
        "employer-supplied brand and interview guidelines."
    ),
}


# --- Question generation (role / JD aware) ---

ROLE_QUESTION_GEN_SYSTEM = Template(
    """You are a $persona_label interviewer for hiring.
Persona focus: $persona_description

Generate interview questions that are grounded in the provided role title and job description.
Prefer questions that reveal real job-relevant capability, not trivia.
Return structured questions only; do not invent employer-specific confidential details."""
)

ROLE_QUESTION_GEN_USER = Template(
    """Role title: $role_title
Seniority: $seniority
Department: $department
Persona: $persona

Job description:
$job_description

Skills to emphasize: $skills
Question types: $question_types
Difficulty: $difficulty
Count: $count
Language: $language

Additional instructions:
$instructions"""
)


# --- Job description drafting ---

JD_DRAFT_SYSTEM = Template(
    """You are a $persona_label job-description writer.
Persona focus: $persona_description

Draft a clear, inclusive, accurate job description.
Avoid biased language, inflated requirements, and discriminatory phrasing.
Use concise sections and actionable responsibility bullets."""
)

JD_DRAFT_USER = Template(
    """Role title: $role_title
Seniority: $seniority
Department: $department
Employment type: $employment_type
Location: $location
Persona tone: $persona

Must-have skills: $must_have_skills
Nice-to-have skills: $nice_to_have_skills
Responsibilities hints: $responsibilities
Company context: $company_context
Tone notes: $tone_notes
Language: $language

Output sections: summary, responsibilities, requirements, nice_to_have, benefits."""
)


def render_role_question_prompts(
    *,
    persona: Persona,
    role_title: str,
    seniority: str,
    department: str,
    job_description: str,
    skills: list[str],
    question_types: list[str],
    difficulty: str,
    count: int,
    language: str,
    instructions: str,
) -> tuple[str, str]:
    label = persona.value.replace("_", " ").title()
    system = ROLE_QUESTION_GEN_SYSTEM.substitute(
        persona_label=label,
        persona_description=PERSONA_DESCRIPTIONS[persona],
    )
    user = ROLE_QUESTION_GEN_USER.substitute(
        role_title=role_title,
        seniority=seniority or "unspecified",
        department=department or "unspecified",
        persona=persona.value,
        job_description=job_description,
        skills=", ".join(skills) if skills else "derive from JD",
        question_types=", ".join(question_types),
        difficulty=difficulty,
        count=count,
        language=language,
        instructions=instructions or "none",
    )
    return system, user


def render_jd_draft_prompts(
    *,
    persona: Persona,
    role_title: str,
    seniority: str,
    department: str,
    employment_type: str,
    location: str,
    must_have_skills: list[str],
    nice_to_have_skills: list[str],
    responsibilities: list[str],
    company_context: str,
    tone_notes: str,
    language: str,
) -> tuple[str, str]:
    label = persona.value.replace("_", " ").title()
    system = JD_DRAFT_SYSTEM.substitute(
        persona_label=label,
        persona_description=PERSONA_DESCRIPTIONS[persona],
    )
    user = JD_DRAFT_USER.substitute(
        role_title=role_title,
        seniority=seniority or "unspecified",
        department=department or "unspecified",
        employment_type=employment_type,
        location=location or "unspecified",
        persona=persona.value,
        must_have_skills=", ".join(must_have_skills) if must_have_skills else "none provided",
        nice_to_have_skills=(
            ", ".join(nice_to_have_skills) if nice_to_have_skills else "none provided"
        ),
        responsibilities=(
            "; ".join(responsibilities) if responsibilities else "derive from role title"
        ),
        company_context=company_context or "none",
        tone_notes=tone_notes or "none",
        language=language,
    )
    return system, user
