"""Markdown generation for interview results."""

from datetime import datetime


def generate_markdown(
    conversation_turns: list[dict],
    interviewer_name: str,
    interviewee_name: str,
    evaluation: str | None,
    evaluator_model: str,
) -> str:
    """Generate a markdown report of the interview.

    Args:
        conversation_turns: List of turn dicts with 'agent', 'turn', 'response' keys.
        interviewer_name: Display name of the interviewer.
        interviewee_name: Display name of the interviewee.
        evaluation: Evaluation text, or None if evaluation has not been run.
        evaluator_model: Model used for evaluation.

    Returns:
        Complete markdown string.
    """
    interviewer_count = sum(
        1 for t in conversation_turns if t["agent"] == interviewer_name
    )
    interviewee_count = sum(
        1 for t in conversation_turns if t["agent"] == interviewee_name
    )

    md = f"""# When AI Meets AI: An Interview Experiment

**Date:** {datetime.now().strftime('%B %d, %Y at %H:%M')}
**Participants:** {interviewer_name} (Interviewer) \u2194 {interviewee_name} (Interviewee)
**Evaluator:** {evaluator_model}
**Total Exchanges:** {len(conversation_turns)} turns

---

## Quick Stats

- **{interviewer_name} contributions:** {interviewer_count} turns
- **{interviewee_name} contributions:** {interviewee_count} turns
- **Interview style:** Free-flowing capability assessment

---

## The Full Conversation

"""

    for turn_data in conversation_turns:
        emoji = "\U0001f7e2" if turn_data["agent"] == interviewer_name else "\U0001f535"
        md += f"### {emoji} Turn {turn_data['turn']}: {turn_data['agent']}\n\n"
        md += f"{turn_data['response']}\n\n"

    evaluation_text = evaluation if evaluation is not None else "_Evaluation not yet run._"

    md += f"""---

## Evaluation

{evaluation_text}

---

*Generated by [llm-talk](https://github.com/am1t/llm-talk)*
"""
    return md
