"""
Physical Activity Events
Activity events focused on physical fitness and sports (ages 6-100)

Events:
- joinSoccerTeam: Join soccer team with practice schedule (ages 6-18)
- soccerProgress: Progress event for soccer team members
- learnMartialArts: Sign up for martial arts classes (ages 6-40)
- martialArtsProgress: Progress event for martial arts students
- runningHabit: Start a running routine (ages 12-70)
- runningProgress: Progress event for runners
- joinGym: Join a gym with membership options (ages 16-100)
- gymProgress: Progress event for gym members
- yogaClass: Try yoga with regular class option (ages 14-100)
- yogaProgress: Progress event for yoga practitioners
"""

import random
import uuid
from events.base import messageFunction, questionFunction, answerOption


# ============================================================
# Physical Activity Class Definition
# ============================================================

class PhysicalActivity:
    """
    Physical activity definition (similar to ExtraCurricular)

    Attributes:
        id: Unique identifier
        title: Activity name
        type: Activity type ('physical_activity')
        focus: Default focus type
        description: Description of the activity
        energyModifier: Energy cost
        image: Optional image URL
    """
    def __init__(self, title, focus, description, energyModifier, image=None):
        self.id = uuid.uuid4().hex
        self.title = title
        self.image = image
        self.type = 'physical_activity'
        self.focus = focus
        self.description = description
        self.energyModifier = energyModifier


def joinSoccerTeam(player, type='message', message=False, response=False):
    """Join soccer team with practice schedule (ages 6-18)"""
    from functions import scheduler, ActivityRecord, find_where

    fname = 'joinSoccerTeam'

    # Check if already on soccer team
    already_member = any(
        getattr(activity, 'title', None) == 'Soccer Team'
        for activity in player.c.activities
    )

    check = (fname not in player.askedQuestions and
             not already_member and
             player.c.ageYears >= 6 and
             player.c.ageYears <= 18 and
             player.c.occupation == 'student' and
             1 >= random.random() * 1000)

    message = "Would you like to join the soccer team?"

    if type != 'answer':
        answerOptions = [
            answerOption("Yes, join the team!", data="join", energyCost=10),
            answerOption("No, not interested", data="no"),
            answerOption("Try out and see", data="tryout", energyCost=5)
        ]
        return questionFunction(fname, message, player, check, answerOptions)

    elif type == 'answer':
        if response['data'] == 'join':
            player.c.social += 15
            player.c.energy -= 10
            player.c.health += 10

            # Create soccer team activity object
            soccer_activity = PhysicalActivity(
                title="Soccer Team",
                focus="Balanced",
                description="School soccer team with regular practice and games",
                energyModifier=15
            )

            # Add activity and activity record
            player.c.activities.append(soccer_activity)
            player.c.activityRecords.append(
                ActivityRecord(soccer_activity.id, soccer_activity.type, player.date)
            )

            # Create recurring practice schedule (2x per week)
            player.c.schedules.append(
                scheduler(
                    player.c,
                    "Soccer Practice",
                    ["twice-week", "afternoon", "weekday"],
                    location="school" + player.c.id,
                    duration=random.randint(30, 60)
                )
            )

            # Update peak energy calculation
            from stats.stats_manager import getPeakEnergy
            getPeakEnergy(player.c)

            player.messageQueue.append("You joined the soccer team! Practice is twice a week.")

        elif response['data'] == 'tryout':
            player.c.social += 5
            player.c.energy -= 5
            player.messageQueue.append("You tried out for the team and had fun!")

        else:  # no
            player.c.happiness -= 5
            player.messageQueue.append("You decided not to join the soccer team.")


def soccerProgress(player, type='message', message=False, response=False):
    """Progress event for soccer team members"""
    from functions import find_where

    fname = 'soccerProgress'

    # Check if on soccer team
    soccer_activity = None
    for activity in player.c.activities:
        if getattr(activity, 'title', None) == 'Soccer Team':
            soccer_activity = activity
            break

    # Find activity record
    activity_record = None
    if soccer_activity:
        for record in player.c.activityRecords:
            if record.id == soccer_activity.id:
                activity_record = record
                break

    check = (fname not in player.events and
             soccer_activity is not None and
             activity_record is not None and
             player.c.ageYears >= 6 and
             player.c.ageYears <= 18 and
             1 >= random.random() * 500)

    if not check:
        return None

    # Determine event based on performance and focus
    performance = activity_record.performance
    focus = activity_record.focus

    if performance < 30:
        message = "You're struggling at soccer practice. Your teammates are way ahead of you."
        if type != 'answer':
            answerOptions = [
                answerOption("Practice harder!", data="practice", energyCost=15),
                answerOption("Ask coach for tips", data="coach"),
                answerOption("Just do your best", data="accept")
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'practice':
                activity_record.performance += 15
                player.c.energy -= 15
                player.c.health += 5
                player.messageQueue.append("You put in extra practice time. Your skills are improving!")
            elif response['data'] == 'coach':
                activity_record.performance += 10
                player.c.social += 5
                player.messageQueue.append("The coach gives you some helpful pointers. You're getting better!")
            else:
                activity_record.performance += 5
                player.messageQueue.append("You accept your current level and just have fun playing.")

    elif performance >= 70:
        message = "You're becoming one of the best players on the soccer team!"
        if type != 'answer':
            answerOptions = [
                answerOption("Train even harder!", data="train", energyCost=20),
                answerOption("Help weaker teammates", data="help"),
                answerOption("Enjoy the success", data="enjoy")
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'train':
                activity_record.performance += 10
                player.c.energy -= 20
                player.c.health += 10
                player.messageQueue.append("Your dedication pays off! You're now a star player!")
            elif response['data'] == 'help':
                activity_record.performance += 5
                player.c.social += 15
                player.messageQueue.append("Helping your teammates makes everyone better. You're a true team player!")
            else:
                player.c.happiness += 15
                player.messageQueue.append("You enjoy being good at soccer. It feels great!")

    else:
        message = "Soccer practice is going well. You're making steady progress."
        if type != 'answer':
            answerOptions = [
                answerOption("Focus on teamwork", data="team"),
                answerOption("Work on skills", data="skills", energyCost=10),
                answerOption("Just have fun", data="fun")
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'team':
                activity_record.performance += 5
                player.c.social += 10
                player.messageQueue.append("Working with your team improves your coordination!")
            elif response['data'] == 'skills':
                activity_record.performance += 10
                player.c.energy -= 10
                player.c.health += 5
                player.messageQueue.append("Extra drills pay off. Your skills are improving!")
            else:
                player.c.happiness += 10
                player.messageQueue.append("Soccer is fun! You enjoy every practice.")


def learnMartialArts(player, type='message', message=False, response=False):
    """Sign up for martial arts classes (ages 6-40)"""
    from functions import scheduler, ActivityRecord

    fname = 'learnMartialArts'

    # Check if already in martial arts
    already_member = any(
        getattr(activity, 'title', None) == 'Martial Arts'
        for activity in player.c.activities
    )

    check = (fname not in player.askedQuestions and
             not already_member and
             player.c.ageYears >= 6 and
             player.c.ageYears <= 40 and
             1 >= random.random() * 1000)

    message = "A martial arts dojo is offering beginner classes. Want to try?"

    if type != 'answer':
        answerOptions = [
            answerOption("Yes, sign up!", data="signup", energyCost=15, moneyCost=100),
            answerOption("No thanks", data="no"),
            answerOption("Watch a class first", data="watch")
        ]
        return questionFunction(fname, message, player, check, answerOptions)

    elif type == 'answer':
        if response['data'] == 'signup':
            player.c.energy -= 15
            player.c.health += 10
            player.c.happiness += 10
            player.c.money -= 100

            # Create martial arts activity object
            martial_arts_activity = PhysicalActivity(
                title="Martial Arts",
                focus="Work Hard",
                description="Martial arts training with regular classes",
                energyModifier=20
            )

            # Add activity and activity record
            player.c.activities.append(martial_arts_activity)
            player.c.activityRecords.append(
                ActivityRecord(martial_arts_activity.id, martial_arts_activity.type, player.date)
            )

            # Create ongoing classes schedule
            player.c.schedules.append(
                scheduler(
                    player.c,
                    "Martial Arts Class",
                    ["twice-week", "evening"],
                    location="dojo" + player.c.id,
                    duration=random.randint(40, 60)
                )
            )

            # Update peak energy calculation
            from stats.stats_manager import getPeakEnergy
            getPeakEnergy(player.c)

            player.messageQueue.append("You signed up for martial arts classes! Training begins soon.")

        elif response['data'] == 'watch':
            player.c.social += 5
            player.messageQueue.append("You watched a class and found it interesting!")

        else:  # no
            player.c.happiness -= 5
            player.messageQueue.append("You decided martial arts isn't for you right now.")


def martialArtsProgress(player, type='message', message=False, response=False):
    """Progress event for martial arts students"""
    fname = 'martialArtsProgress'

    # Check if in martial arts
    martial_arts_activity = None
    for activity in player.c.activities:
        if getattr(activity, 'title', None) == 'Martial Arts':
            martial_arts_activity = activity
            break

    # Find activity record
    activity_record = None
    if martial_arts_activity:
        for record in player.c.activityRecords:
            if record.id == martial_arts_activity.id:
                activity_record = record
                break

    check = (fname not in player.events and
             martial_arts_activity is not None and
             activity_record is not None and
             player.c.ageYears >= 6 and
             player.c.ageYears <= 40 and
             1 >= random.random() * 500)

    if not check:
        return None

    # Determine event based on performance
    performance = activity_record.performance

    if performance < 30:
        message = "The martial arts forms are harder than you expected. You keep making mistakes."
        if type != 'answer':
            answerOptions = [
                answerOption("Practice at home", data="practice", energyCost=15),
                answerOption("Ask sensei for help", data="sensei"),
                answerOption("Keep trying", data="keep")
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'practice':
                activity_record.performance += 15
                player.c.energy -= 15
                player.c.health += 5
                player.messageQueue.append("Extra practice helps! Your forms are getting smoother.")
            elif response['data'] == 'sensei':
                activity_record.performance += 12
                player.c.social += 5
                player.messageQueue.append("Your sensei provides guidance. You're improving!")
            else:
                activity_record.performance += 7
                player.messageQueue.append("Persistence pays off. You're slowly getting better.")

    elif performance >= 70:
        message = "Your sensei says you're ready to test for your next belt!"
        if type != 'answer':
            answerOptions = [
                answerOption("Train intensely for test", data="train", energyCost=25),
                answerOption("Take the test", data="test", energyCost=15),
                answerOption("Wait until ready", data="wait")
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'train':
                activity_record.performance += 10
                player.c.energy -= 25
                player.c.health += 10
                player.messageQueue.append("Your intense training pays off! You pass the belt test with flying colors!")
            elif response['data'] == 'test':
                activity_record.performance += 5
                player.c.energy -= 15
                player.c.happiness += 20
                player.messageQueue.append("You passed! You earned your next belt!")
            else:
                player.c.happiness += 5
                player.messageQueue.append("You'll take the test when you feel more confident.")

    else:
        message = "Your martial arts training is going well. You're developing discipline and skill."
        if type != 'answer':
            answerOptions = [
                answerOption("Focus on strength", data="strength", energyCost=15),
                answerOption("Practice with partner", data="partner"),
                answerOption("Master the basics", data="basics", energyCost=10)
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'strength':
                activity_record.performance += 7
                player.c.energy -= 15
                player.c.health += 10
                player.messageQueue.append("Building strength enhances your technique!")
            elif response['data'] == 'partner':
                activity_record.performance += 8
                player.c.social += 10
                player.messageQueue.append("Partner training improves your reflexes and timing!")
            else:
                activity_record.performance += 10
                player.c.energy -= 10
                player.messageQueue.append("Perfecting the basics makes everything else easier!")


def runningHabit(player, type='message', message=False, response=False):
    """Start a running routine (ages 12-70)"""
    from functions import scheduler, ActivityRecord

    fname = 'runningHabit'

    # Check if already running
    already_running = any(
        getattr(activity, 'title', None) == 'Running'
        for activity in player.c.activities
    )

    check = (fname not in player.askedQuestions and
             not already_running and
             player.c.ageYears >= 12 and
             player.c.ageYears <= 70 and
             1 >= random.random() * 1000)

    message = "You're thinking about starting a running routine. Do it?"

    if type != 'answer':
        answerOptions = [
            answerOption("Yes, start running daily", data="daily", energyCost=10),
            answerOption("Run occasionally", data="occasional"),
            answerOption("No, too much effort", data="no")
        ]
        return questionFunction(fname, message, player, check, answerOptions)

    elif type == 'answer':
        if response['data'] == 'daily':
            player.c.health += 20
            player.c.energy -= 10

            # Create running activity object
            running_activity = PhysicalActivity(
                title="Running",
                focus="Balanced",
                description="Daily running routine for health and fitness",
                energyModifier=12
            )

            # Add activity and activity record
            player.c.activities.append(running_activity)
            player.c.activityRecords.append(
                ActivityRecord(running_activity.id, running_activity.type, player.date)
            )

            # Create daily running schedule
            player.c.schedules.append(
                scheduler(
                    player.c,
                    "Morning Run",
                    ["daily", "morning"],
                    location="outside" + player.c.id,
                    duration=random.randint(20, 40)
                )
            )

            # Update peak energy calculation
            from stats.stats_manager import getPeakEnergy
            getPeakEnergy(player.c)

            player.messageQueue.append("You started a daily running routine!")

        elif response['data'] == 'occasional':
            player.c.health += 10
            player.messageQueue.append("You'll run occasionally when you feel like it.")

        else:  # no
            player.c.happiness -= 5
            player.messageQueue.append("You decided running is too much effort.")


def runningProgress(player, type='message', message=False, response=False):
    """Progress event for runners"""
    fname = 'runningProgress'

    # Check if running
    running_activity = None
    for activity in player.c.activities:
        if getattr(activity, 'title', None) == 'Running':
            running_activity = activity
            break

    # Find activity record
    activity_record = None
    if running_activity:
        for record in player.c.activityRecords:
            if record.id == running_activity.id:
                activity_record = record
                break

    check = (fname not in player.events and
             running_activity is not None and
             activity_record is not None and
             player.c.ageYears >= 12 and
             player.c.ageYears <= 70 and
             1 >= random.random() * 500)

    if not check:
        return None

    # Determine event based on performance
    performance = activity_record.performance

    if performance < 30:
        message = "Running is harder than you thought. You're out of breath quickly."
        if type != 'answer':
            answerOptions = [
                answerOption("Push through it", data="push", energyCost=15),
                answerOption("Slow down, build gradually", data="slow"),
                answerOption("Take a break", data="break")
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'push':
                activity_record.performance += 12
                player.c.energy -= 15
                player.c.health += 5
                player.messageQueue.append("Pushing yourself builds endurance! You're getting stronger.")
            elif response['data'] == 'slow':
                activity_record.performance += 15
                player.c.health += 8
                player.messageQueue.append("Building gradually prevents injury. Your stamina is improving!")
            else:
                player.c.happiness += 5
                player.messageQueue.append("Taking a break helps you recover and come back stronger.")

    elif performance >= 70:
        message = "You're in great running shape! Consider a challenge?"
        if type != 'answer':
            answerOptions = [
                answerOption("Train for 5K race", data="race", energyCost=20),
                answerOption("Increase distance", data="distance", energyCost=15),
                answerOption("Maintain current level", data="maintain")
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'race':
                activity_record.performance += 10
                player.c.energy -= 20
                player.c.health += 15
                player.c.happiness += 25
                player.messageQueue.append("You completed your first 5K race! What an accomplishment!")
            elif response['data'] == 'distance':
                activity_record.performance += 8
                player.c.energy -= 15
                player.c.health += 10
                player.messageQueue.append("Increasing your distance challenges you and builds endurance!")
            else:
                player.c.happiness += 10
                player.messageQueue.append("You enjoy your current routine. Consistency is key!")

    else:
        message = "Your running routine is going well. You're making steady progress."
        if type != 'answer':
            answerOptions = [
                answerOption("Focus on speed", data="speed", energyCost=15),
                answerOption("Run with a friend", data="friend"),
                answerOption("Enjoy the scenery", data="scenery")
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'speed':
                activity_record.performance += 10
                player.c.energy -= 15
                player.c.health += 8
                player.messageQueue.append("Speed work improves your cardiovascular fitness!")
            elif response['data'] == 'friend':
                activity_record.performance += 7
                player.c.social += 15
                player.messageQueue.append("Running with a friend makes it more fun and keeps you accountable!")
            else:
                player.c.happiness += 15
                player.c.stress -= 10
                player.messageQueue.append("Running in nature brings peace and clarity to your mind.")


def joinGym(player, type='message', message=False, response=False):
    """Join a gym with membership options (ages 16-100)"""
    from functions import scheduler, ActivityRecord

    fname = 'joinGym'

    # Check if already gym member
    already_member = any(
        getattr(activity, 'title', None) == 'Gym Membership'
        for activity in player.c.activities
    )

    check = (fname not in player.askedQuestions and
             not already_member and
             player.c.ageYears >= 16 and
             player.c.ageYears <= 100 and
             1 >= random.random() * 1000)

    message = "The local gym is offering memberships. Join?"

    if type != 'answer':
        answerOptions = [
            answerOption("Yes, full membership!", data="full", moneyCost=50, energyCost=10),
            answerOption("Yes, basic plan", data="basic", moneyCost=25),
            answerOption("No, workout at home", data="home"),
            answerOption("Not interested", data="no")
        ]
        return questionFunction(fname, message, player, check, answerOptions)

    elif type == 'answer':
        if response['data'] == 'full':
            player.c.money -= 50
            player.c.health += 15
            player.c.energy -= 10

            # Create gym activity object
            gym_activity = PhysicalActivity(
                title="Gym Membership",
                focus="Work Hard",
                description="Full gym membership with access to all equipment and classes",
                energyModifier=18
            )

            # Add activity and activity record
            player.c.activities.append(gym_activity)
            player.c.activityRecords.append(
                ActivityRecord(gym_activity.id, gym_activity.type, player.date)
            )

            # Create gym schedule
            player.c.schedules.append(
                scheduler(
                    player.c,
                    "Gym Workout",
                    ["thrice-week", "evening"],
                    location="gym" + player.c.id,
                    duration=random.randint(45, 90)
                )
            )

            # Update peak energy calculation
            from stats.stats_manager import getPeakEnergy
            getPeakEnergy(player.c)

            player.messageQueue.append("You got a full gym membership! Time to get fit.")

        elif response['data'] == 'basic':
            player.c.money -= 25
            player.c.health += 10

            # Create gym activity object (basic)
            gym_activity = PhysicalActivity(
                title="Gym Membership",
                focus="Balanced",
                description="Basic gym membership with access to standard equipment",
                energyModifier=12
            )

            # Add activity and activity record
            player.c.activities.append(gym_activity)
            player.c.activityRecords.append(
                ActivityRecord(gym_activity.id, gym_activity.type, player.date)
            )

            # Create lighter gym schedule
            player.c.schedules.append(
                scheduler(
                    player.c,
                    "Gym Workout",
                    ["twice-week", "evening"],
                    location="gym" + player.c.id,
                    duration=random.randint(30, 60)
                )
            )

            # Update peak energy calculation
            from stats.stats_manager import getPeakEnergy
            getPeakEnergy(player.c)

            player.messageQueue.append("You got a basic gym membership!")

        elif response['data'] == 'home':
            player.c.health += 5
            player.messageQueue.append("You'll workout at home instead.")

        else:  # no
            player.c.happiness -= 5
            player.messageQueue.append("You decided not to join a gym.")


def gymProgress(player, type='message', message=False, response=False):
    """Progress event for gym members"""
    fname = 'gymProgress'

    # Check if gym member
    gym_activity = None
    for activity in player.c.activities:
        if getattr(activity, 'title', None) == 'Gym Membership':
            gym_activity = activity
            break

    # Find activity record
    activity_record = None
    if gym_activity:
        for record in player.c.activityRecords:
            if record.id == gym_activity.id:
                activity_record = record
                break

    check = (fname not in player.events and
             gym_activity is not None and
             activity_record is not None and
             player.c.ageYears >= 16 and
             player.c.ageYears <= 100 and
             1 >= random.random() * 500)

    if not check:
        return None

    # Determine event based on performance
    performance = activity_record.performance

    if performance < 30:
        message = "You're not seeing the gym results you hoped for. Feeling discouraged?"
        if type != 'answer':
            answerOptions = [
                answerOption("Hire a personal trainer", data="trainer", moneyCost=100, energyCost=15),
                answerOption("Watch technique videos", data="videos"),
                answerOption("Keep at it", data="keep")
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'trainer':
                activity_record.performance += 20
                player.c.money -= 100
                player.c.energy -= 15
                player.c.health += 10
                player.messageQueue.append("A trainer shows you proper form and creates a plan. You're making real progress now!")
            elif response['data'] == 'videos':
                activity_record.performance += 12
                player.c.health += 5
                player.messageQueue.append("Learning proper technique makes a huge difference!")
            else:
                activity_record.performance += 8
                player.messageQueue.append("Consistency is key. You're building good habits.")

    elif performance >= 70:
        message = "You're in great shape! The gym is really paying off!"
        if type != 'answer':
            answerOptions = [
                answerOption("Train for competition", data="compete", energyCost=25),
                answerOption("Try advanced workouts", data="advanced", energyCost=20),
                answerOption("Maintain and enjoy", data="maintain")
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'compete':
                activity_record.performance += 10
                player.c.energy -= 25
                player.c.health += 15
                player.c.happiness += 20
                player.messageQueue.append("Training for competition pushes you to new heights!")
            elif response['data'] == 'advanced':
                activity_record.performance += 8
                player.c.energy -= 20
                player.c.health += 12
                player.messageQueue.append("Advanced workouts challenge you in new ways!")
            else:
                player.c.happiness += 15
                player.messageQueue.append("You love your current fitness level and routine!")

    else:
        message = "Your gym workouts are going well. Seeing steady improvement!"
        if type != 'answer':
            answerOptions = [
                answerOption("Focus on strength", data="strength", energyCost=15),
                answerOption("Join a class", data="class"),
                answerOption("Try new equipment", data="equipment", energyCost=10)
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'strength':
                activity_record.performance += 10
                player.c.energy -= 15
                player.c.health += 10
                player.messageQueue.append("Building strength transforms your physique!")
            elif response['data'] == 'class':
                activity_record.performance += 8
                player.c.social += 15
                player.c.happiness += 10
                player.messageQueue.append("Group classes are motivating and fun!")
            else:
                activity_record.performance += 9
                player.c.energy -= 10
                player.messageQueue.append("Trying new equipment keeps your workouts fresh and engaging!")


def yogaClass(player, type='message', message=False, response=False):
    """Try yoga with regular class option (ages 14-100)"""
    from functions import scheduler, ActivityRecord

    fname = 'yogaClass'

    # Check if already in yoga
    already_member = any(
        getattr(activity, 'title', None) == 'Yoga'
        for activity in player.c.activities
    )

    check = (fname not in player.askedQuestions and
             not already_member and
             player.c.ageYears >= 14 and
             player.c.ageYears <= 100 and
             1 >= random.random() * 1000)

    message = "A friend invites you to try a yoga class. Go?"

    if type != 'answer':
        answerOptions = [
            answerOption("Yes, try it out!", data="tryout", energyCost=5),
            answerOption("No, not my thing", data="no"),
            answerOption("Sign up for regular classes", data="regular", moneyCost=40)
        ]
        return questionFunction(fname, message, player, check, answerOptions)

    elif type == 'answer':
        if response['data'] == 'tryout':
            player.c.energy -= 5
            player.c.happiness += 15
            player.c.social += 10
            player.messageQueue.append("You tried yoga and loved it!")

        elif response['data'] == 'regular':
            player.c.money -= 40
            player.c.happiness += 20
            player.c.stress -= 20

            # Create yoga activity object
            yoga_activity = PhysicalActivity(
                title="Yoga",
                focus="Balanced",
                description="Regular yoga classes for flexibility, strength, and mindfulness",
                energyModifier=10
            )

            # Add activity and activity record
            player.c.activities.append(yoga_activity)
            player.c.activityRecords.append(
                ActivityRecord(yoga_activity.id, yoga_activity.type, player.date)
            )

            # Create yoga class schedule
            player.c.schedules.append(
                scheduler(
                    player.c,
                    "Yoga Class",
                    ["twice-week", "evening"],
                    location="yogastudio" + player.c.id,
                    duration=random.randint(45, 60)
                )
            )

            # Update peak energy calculation
            from stats.stats_manager import getPeakEnergy
            getPeakEnergy(player.c)

            player.messageQueue.append("You signed up for regular yoga classes!")

        else:  # no
            player.c.social -= 5
            player.messageQueue.append("You decided yoga isn't for you.")


def yogaProgress(player, type='message', message=False, response=False):
    """Progress event for yoga practitioners"""
    fname = 'yogaProgress'

    # Check if in yoga
    yoga_activity = None
    for activity in player.c.activities:
        if getattr(activity, 'title', None) == 'Yoga':
            yoga_activity = activity
            break

    # Find activity record
    activity_record = None
    if yoga_activity:
        for record in player.c.activityRecords:
            if record.id == yoga_activity.id:
                activity_record = record
                break

    check = (fname not in player.events and
             yoga_activity is not None and
             activity_record is not None and
             player.c.ageYears >= 14 and
             player.c.ageYears <= 100 and
             1 >= random.random() * 500)

    if not check:
        return None

    # Determine event based on performance
    performance = activity_record.performance

    if performance < 30:
        message = "Some of the yoga poses are challenging. You're not as flexible as others in class."
        if type != 'answer':
            answerOptions = [
                answerOption("Practice at home", data="practice", energyCost=10),
                answerOption("Ask instructor for modifications", data="modify"),
                answerOption("Be patient with yourself", data="patient")
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'practice':
                activity_record.performance += 15
                player.c.energy -= 10
                player.c.stress -= 10
                player.messageQueue.append("Home practice helps you build flexibility gradually!")
            elif response['data'] == 'modify':
                activity_record.performance += 12
                player.c.social += 5
                player.messageQueue.append("Your instructor shows you modifications that work for your body!")
            else:
                activity_record.performance += 10
                player.c.happiness += 10
                player.messageQueue.append("Yoga is about progress, not perfection. You're doing great!")

    elif performance >= 70:
        message = "You've become quite skilled at yoga! Your practice has deepened."
        if type != 'answer':
            answerOptions = [
                answerOption("Try advanced classes", data="advanced", energyCost=15),
                answerOption("Learn to teach yoga", data="teach", moneyCost=200),
                answerOption("Deepen meditation practice", data="meditate")
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'advanced':
                activity_record.performance += 10
                player.c.energy -= 15
                player.c.health += 12
                player.c.stress -= 15
                player.messageQueue.append("Advanced yoga challenges you in new ways and brings profound peace!")
            elif response['data'] == 'teach':
                activity_record.performance += 8
                player.c.money -= 200
                player.c.social += 20
                player.c.happiness += 20
                player.messageQueue.append("You completed yoga teacher training! Now you can share this practice with others!")
            else:
                player.c.stress -= 25
                player.c.happiness += 15
                player.messageQueue.append("Deepening your meditation brings incredible peace and clarity!")

    else:
        message = "Your yoga practice is going well. You're feeling more flexible and centered."
        if type != 'answer':
            answerOptions = [
                answerOption("Focus on flexibility", data="flexibility", energyCost=10),
                answerOption("Build strength poses", data="strength", energyCost=15),
                answerOption("Emphasize mindfulness", data="mindfulness")
            ]
            return questionFunction(fname, message, player, check, answerOptions)
        elif type == 'answer':
            if response['data'] == 'flexibility':
                activity_record.performance += 10
                player.c.energy -= 10
                player.c.health += 8
                player.messageQueue.append("Working on flexibility opens up new poses for you!")
            elif response['data'] == 'strength':
                activity_record.performance += 12
                player.c.energy -= 15
                player.c.health += 12
                player.messageQueue.append("Strength-building poses transform your practice and body!")
            else:
                activity_record.performance += 8
                player.c.stress -= 20
                player.c.happiness += 15
                player.messageQueue.append("Mindful yoga brings deep peace and mental clarity!")


__all__ = [
    'joinSoccerTeam',
    'soccerProgress',
    'learnMartialArts',
    'martialArtsProgress',
    'runningHabit',
    'runningProgress',
    'joinGym',
    'gymProgress',
    'yogaClass',
    'yogaProgress',
]
