#!/usr/bin/env python3
"""
Pixelated Empathy — Group Therapy Session Generator

Fills Gap 4: group therapy sessions.
5 group types × 50 sessions = 250 sessions total.
3-5 patients per group. Multi-patient format with name-tagged messages.
Vary turns 16-24. Naturalistic turn-taking.

Usage:
  python generate_group_sessions.py [--categories all] [--sessions-per-category 50] [--resume]
"""

from session_base_multi import run_multi_generation

CATEGORIES = {
    "process_group": {
        "name": "Process Group Therapy",
        "difficulty": "medium-high",
        "presentations": [
            "interpersonal conflict between two members — tension from last week, group processes the rupture in real time",
            "new member integration — someone joined recently, group dynamics shifting, old members guarded",
            "shared vulnerability moment — one member's disclosure opens the door for others to share similar experiences",
            "resistance and defensiveness — a member intellectualizes to avoid feeling, group gently challenges",
            "here-and-now focus — therapist redirects from storytelling to present-moment interactions between members",
        ],
        "persona_sets": [
            [
                {
                    "name": "Sarah",
                    "age": "34",
                    "gender": "female",
                    "occupation": "nurse",
                    "presenting": "Conflict with another member who reminded her of her mother",
                },
                {
                    "name": "Marcus",
                    "age": "42",
                    "gender": "male",
                    "occupation": "teacher",
                    "presenting": "New to group, guarded, testing whether it's safe to share",
                },
                {
                    "name": "Devon",
                    "age": "28",
                    "gender": "non-binary",
                    "occupation": "barista",
                    "presenting": "Opened up last week, feeling exposed and considering not coming back",
                },
                {
                    "name": "Lisa",
                    "age": "50",
                    "gender": "female",
                    "occupation": "retired social worker",
                    "presenting": "Long-time member, tries to be the group caretaker, avoids her own work",
                },
                {
                    "name": "James",
                    "age": "36",
                    "gender": "male",
                    "occupation": "engineer",
                    "presenting": "Intellectualizes everything, group is challenging him to feel",
                },
            ],
        ],
        "therapist_techniques": [
            "here-and-now processing — redirect from storytelling to present-moment group dynamics",
            "interpersonal feedback — members give each other direct feedback about their impact",
            "group cohesion building — highlight shared experiences, build connection",
            "process illumination — name the pattern happening in the room in real time",
            "bridging — connect one member's experience to another's to build universality",
            "working through resistance — gently name avoidance without forcing disclosure",
        ],
        "therapist_prompt_addon": (
            "You facilitate a process therapy group. You focus on the here-and-now — what's happening "
            "between members in this room right now. You don't let the group become individual therapy "
            "with an audience. You redirect storytelling to present-moment interactions. You encourage "
            "members to give each other feedback. You name patterns as they emerge. You balance participation "
            "so quieter members aren't drowned out."
        ),
    },
    "dbt_skills_group": {
        "name": "DBT Skills Group",
        "difficulty": "medium",
        "presentations": [
            "emotion regulation module — practicing identifying and labeling emotions, members share struggles with impluse",
            "distress tolerance — learning crisis survival skills, members role-play accepting reality they can't change",
            "interpersonal effectiveness — practicing DEAR MAN, members work through real interpersonal scenarios",
            "mindfulness practice — group does mindfulness exercise, processes resistance to being present",
            "homework review — members share DBT diary cards, therapist coaches on skills application from the week",
        ],
        "persona_sets": [
            [
                {
                    "name": "Rachel",
                    "age": "25",
                    "gender": "female",
                    "occupation": "student",
                    "presenting": "Struggling with emotion regulation, impulsive behaviors when overwhelmed",
                },
                {
                    "name": "Tony",
                    "age": "31",
                    "gender": "male",
                    "occupation": "chef",
                    "presenting": "Anger issues, trying to use distress tolerance before reacting",
                },
                {
                    "name": "Maya",
                    "age": "27",
                    "gender": "female",
                    "occupation": "office manager",
                    "presenting": "Fear of abandonment drives people-pleasing, working on interpersonal effectiveness",
                },
                {
                    "name": "Jordan",
                    "age": "22",
                    "gender": "non-binary",
                    "occupation": "barista",
                    "presenting": "Self-harm history, learning distress tolerance as alternative",
                },
            ],
        ],
        "therapist_techniques": [
            "skills instruction — teach specific DBT skill clearly, check for understanding",
            "behavioral rehearsal — members practice skills on each other with real scenarios",
            "diary card review — go through homework, reinforce skills use, problem-solve barriers",
            "validation — validate the difficulty of using skills while encouraging continued practice",
            "contingency management — reinforce skills use, address non-adherence without shame",
            "group problem-solving — members help each other troubleshoot skills application",
        ],
        "therapist_prompt_addon": (
            "You facilitate a DBT skills group. This is structured and skills-focused, not process-oriented. "
            "You teach specific skills, review homework (diary cards), and have members practice. You balance "
            "teaching with member participation. You validate the difficulty of skills use while maintaining "
            "the structure. You redirect process-oriented sharing back to skills application."
        ),
    },
    "support_group": {
        "name": "Peer Support Group",
        "difficulty": "low-medium",
        "presentations": [
            "shared loss — grief support group, members at different stages, someone new joins",
            "chronic illness support — members share daily challenges, someone had a bad week medically",
            "caregiver support — family caregivers of dementia patients, sharing burnout and guilt",
            "addiction recovery — mutual support group, someone分享了 a close call, processing urges",
            "new diagnosis support — group for recently diagnosed, fear and uncertainty dominate",
        ],
        "persona_sets": [
            [
                {
                    "name": "Patricia",
                    "age": "60",
                    "gender": "female",
                    "occupation": "retired",
                    "presenting": "Lost husband 8 months ago, first time in group, scared and raw",
                },
                {
                    "name": "Robert",
                    "age": "45",
                    "gender": "male",
                    "occupation": "mechanic",
                    "presenting": "Lost his brother 2 years ago, group veteran, here to support others",
                },
                {
                    "name": "Aisha",
                    "age": "33",
                    "gender": "female",
                    "occupation": "teacher",
                    "presenting": "Mother died recently, angry at everyone who still has theirs",
                },
                {
                    "name": "Carlos",
                    "age": "28",
                    "gender": "male",
                    "occupation": "student",
                    "presenting": "Lost friend to overdose, complicated grief, guilt about not saving him",
                },
            ],
        ],
        "therapist_techniques": [
            "universality — highlight shared experience, reduce isolation",
            "active listening modeling — demonstrate and encourage peer-to-peer support",
            "grief education — normalize grief responses, explain non-linear nature",
            "storytelling containment — allow sharing while preventing rumination spirals",
            "mutual aid — facilitate members offering support and resources to each other",
            "closure each session — summarize, validate, provide hope without false promises",
        ],
        "therapist_prompt_addon": (
            "You facilitate a peer support group. Your role is to create safety and structure, not to be the "
            "center of attention. You encourage peer-to-peer connection. You normalize experiences without "
            "minimizing them. You hold space for grief and emotion while keeping the group from spiraling. "
            "You ensure no one dominates or disappears. You provide gentle structure, not rigid control."
        ),
    },
    "trauma_group": {
        "name": "Trauma Processing Group",
        "difficulty": "high",
        "presentations": [
            "narrative sharing — a member shares their trauma narrative for the first time, group holds space",
            "trigger processing — something in the session triggered a member, group supports while therapist contains",
            "avoidance work — a member has been avoiding sharing, group gently invites without pressuring",
            "collective trauma — shared experience (natural disaster, community violence), processing together",
            "shame reduction — member shares something they've never told anyone, group responds with acceptance",
        ],
        "persona_sets": [
            [
                {
                    "name": "Maria",
                    "age": "38",
                    "gender": "female",
                    "occupation": "nurse",
                    "presenting": "Childhood sexual abuse, first time sharing narrative, terrified",
                },
                {
                    "name": "David",
                    "age": "45",
                    "gender": "male",
                    "occupation": "veteran",
                    "presenting": "Combat trauma, avoidance, group is challenging his walls",
                },
                {
                    "name": "Keisha",
                    "age": "29",
                    "gender": "female",
                    "occupation": "social worker",
                    "presenting": "Domestic violence survivor, shame about staying, processing self-blame",
                },
                {
                    "name": "Tom",
                    "age": "33",
                    "gender": "male",
                    "occupation": "firefighter",
                    "presenting": "First responder trauma, thinks he shouldn't need help, group is shifting that",
                },
            ],
        ],
        "therapist_techniques": [
            "trauma-informed pacing — go slow, check in with member, don't push past their window of tolerance",
            "grounding — bring members back to present when triggered, use sensory techniques",
            "containment — manage affect in the room, prevent flooding, keep group safe",
            "cognitive processing — gently explore meaning-making without cognitive restructuring lectures",
            "witnessing — group holds space for the storyteller, validates through presence",
            "safety rebuilding — each session ends with stabilization, not open wounds",
        ],
        "therapist_prompt_addon": (
            "You facilitate a trauma processing group. Safety is paramount — you never push disclosure and "
            "always check in with members' windows of tolerance. You contain affect, prevent flooding, and "
            "ground members when triggered. You end every session with stabilization. You understand that "
            "silence is sometimes processing, not resistance. You're prepared for triggers and have grounding "
            "techniques ready. You NEVER force narrative exposure."
        ),
    },
    "addiction_recovery": {
        "name": "Addiction Recovery Group",
        "difficulty": "medium-high",
        "presentations": [
            "relapse processing — member had a slip, group processes without judgment, reinforces recovery path",
            "urge surfing — member shares current cravings, group coaches through the urge in real time",
            "step work — working through recovery steps together, member stuck on a particular step",
            "lifestyle reconstruction — member struggling to rebuild life without substances, identity questions",
            "family impact — members share how addiction affected relationships, processing guilt and repair",
        ],
        "persona_sets": [
            [
                {
                    "name": "Mike",
                    "age": "40",
                    "gender": "male",
                    "occupation": "construction worker",
                    "presenting": "90 days sober, had a slip last weekend, ashamed and scared",
                },
                {
                    "name": "Dana",
                    "age": "35",
                    "gender": "female",
                    "occupation": "teacher",
                    "presenting": "6 months sober, struggling with cravings, white-knuckling through days",
                },
                {
                    "name": "Marcus",
                    "age": "28",
                    "gender": "male",
                    "occupation": "musician",
                    "presenting": "Lost band and friends to addiction, rebuilding identity without substances",
                },
                {
                    "name": "Tina",
                    "age": "44",
                    "gender": "female",
                    "occupation": "nurse",
                    "presenting": "Processing guilt about impact on her kids, wants to make amends but doesn't know how",
                },
            ],
        ],
        "therapist_techniques": [
            "motivational interviewing — explore ambivalence, reinforce intrinsic motivation",
            "relapse prevention planning — identify triggers, develop coping strategies, normalize slips",
            "urge surfing technique — teach riding the wave of craving without acting on it",
            "harm reduction — meet people where they are, reduce risk even if not fully abstinent",
            "value-based living — connect recovery to what matters, not just what to avoid",
            "amends processing — explore guilt and repair without rushing toward reconciliation",
        ],
        "therapist_prompt_addon": (
            "You facilitate an addiction recovery group. You use motivational interviewing, not confrontation. "
            "You normalize slips as part of the process, not failures. You distinguish lapse from relapse. "
            "You focus on harm reduction and value-based living, not just abstinence. You hold space for "
            "shame while gently challenging it. You never moralize or shame substance use."
        ),
    },
}


def main():
    run_multi_generation(
        categories_dict=CATEGORIES,
        output_dir="data/group_sessions",
        output_filename="group_sessions.jsonl",
        session_id_prefix="group",
        source_family="group_therapy",
        default_sessions_per_category=50,
        description="Group Therapy Session Generation",
        min_turns=16,
        max_turns=24,
        turn_pattern="naturalistic",
    )


if __name__ == "__main__":
    main()
