"""
Moral Dilemma Events
Complex ethical decisions with lasting consequences

Events:
- braceletDilemma: Stolen bracelet dilemma
- bullyDilemma: Bullying intervention dilemma
"""

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


def bullyDilemma(player, type='message', message=False, response=False, dilemma=False):
    """Bullying intervention dilemma"""
    fname = 'bullyDilemma'
    check = fname not in player.askedQuestions and 'school' in player.c.location and player.c.ageYears >= 10 and player.c.ageYears < 18 and 1 >= random.random()*1000
    
    answerOptions = [answerOption('Stand up for your friend',energyCost=5),answerOption("Don't do anything",energyCost=0),answerOption("Join in on the bullying",energyCost=5)]
    if (check and type != 'answer'):
        from functions import get_random_friend, get_random_classmate
        friend = get_random_friend(player)
        if (friend):
            classmate1 = get_random_classmate(player)
            classmate2 = get_random_classmate(player)
            classmate1Name = classmate1.firstname+ ' '+classmate1.lastname
            classmate2Name = classmate2.firstname+ ' '+classmate2.lastname
            dilemma = dilemmaClass(fname,answerOptions)
            dilemma.friend = friend.id
            dilemma.bullies = [classmate1.id,classmate2.id]
            player.activeDilemmas.append(dilemma)
            message = "Your friend "+friend.firstname+ ' '+friend.lastname+ "  is being bullied by popular kids, "+classmate1Name+" and "+classmate2Name+" What do you do?"
            return questionFunction(fname,message,player,check,answerOptions)
    if (type == 'answer'):
        player.activeDilemmas[-1].answer = next((option for option in answerOptions if option.option == response['option']), None)
        player.c.energy -= player.activeDilemmas[-1].answer.energyCost
    if dilemma and hasattr(dilemma, 'step') and dilemma.step == 2:
        from functions import get_person
        friend = get_person(player,dilemma.friend)
        classmate1 = get_person(player,dilemma.bullies[0])
        classmate2 = get_person(player,dilemma.bullies[1])
        classmate1Name = classmate1.firstname+ ' '+classmate1.lastname
        classmate2Name = classmate2.firstname+ ' '+classmate2.lastname
        message = ""
        if (dilemma.answer == answerOptions[0]):
            message = "You stand up for your friend "+friend.firstname+ ' '+friend.lastname+ " and tell the bullies to stop. They stop and leave your friend alone."
        elif (dilemma.answer == answerOptions[1]):
            message = "You don't do anything about the bullying and your friend "+friend.firstname+ ' '+friend.lastname+ " continues to be bullied."
        elif (dilemma.answer == answerOptions[2]):
            message = "You join in on the bullying and your friend "+friend.firstname+ ' '+friend.lastname+ " continues to be bullied."


def braceletDilemma(player, type='message', message=False, response=False, dilemma=False):
    """Stolen bracelet dilemma"""
    fname = 'braceletDilemma'
    check = fname not in player.askedQuestions and 'school' in player.c.location and player.c.ageYears >= 5 and player.c.ageYears < 18 and 1 >= random.random()*1000
    
    answerOptions = [answerOption("Confront her directly about it",energyCost=5),answerOption("Tell the teacher about it",energyCost=3),answerOption("Don't do anything",energyCost=0)]
    if (check and type != 'answer'):
        from functions import get_random_classmate
        classmate1 = get_random_classmate(player)
        classmate1Name = classmate1.firstname+ ' '+classmate1.lastname
        message = "You received a bracelet from your grandmother and wear it to school, but one day it went missing. Today you saw that "+classmate1Name+ "  is wearing it. What do you do?"
        dilemma = dilemmaClass(fname,answerOptions)
        dilemma.classmate = classmate1.id
        player.activeDilemmas.append(dilemma)
        return questionFunction(fname,message,player,check,answerOptions)
    elif (type == 'answer'):
        # add the response to the dilemma in player.activeDilemmas
        player.activeDilemmas[-1].answer = next((option for option in answerOptions if option.option == response['option']), None)
        player.c.energy -= player.activeDilemmas[-1].answer.energyCost
    elif dilemma and hasattr(dilemma, 'step') and hasattr(dilemma, 'answer') and dilemma.step == 2:
        from functions import get_person
        classmate = get_person(player, dilemma.classmate)
        classmate1Name = classmate.firstname + ' ' + classmate.lastname
        
        message = ""

        if dilemma.answer == answerOptions[0]:
            message = "You confront " + classmate1Name + " about the bracelet and she says that she found it on the ground and thought it was pretty. She apologizes and gives it back to you."
        elif dilemma.answer == answerOptions[1]:
            message = "You tell the teacher about the bracelet and she takes it from " + classmate1Name + " and returns it to you."
        elif dilemma.answer == answerOptions[2]:
            message = "You decide not to do anything about the bracelet and " + classmate1Name + " continues to wear it."

        player.messageQueue.append(message)
        player.activeDilemmas.remove(dilemma)


def foundLostPet(player, type='message', message=False, response=False, dilemma=False):
    """Finding someone's lost pet dilemma"""
    fname = 'foundLostPet'
    check = fname not in player.askedQuestions and player.c.ageYears >= 8 and 1 >= random.random()*1000

    answerOptions = [
        answerOption('Take it to vet to scan chip', energyCost=15),
        answerOption('Post on social media'),
        answerOption('Keep the dog'),
        answerOption('Leave it, not your problem')
    ]

    if (check and type != 'answer'):
        message = "You found a lost dog with a collar but no one around. What do you do?"
        dilemma = dilemmaClass(fname, answerOptions)
        player.activeDilemmas.append(dilemma)
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        player.activeDilemmas[-1].answer = next((option for option in answerOptions if option.option == response['option']), None)
        player.c.energy -= player.activeDilemmas[-1].answer.energyCost
    elif dilemma and hasattr(dilemma, 'step') and hasattr(dilemma, 'answer') and dilemma.step == 2:
        message = ""

        if dilemma.answer == answerOptions[0]:
            message = "You take the dog to the vet. They scan the chip and contact the owner. The family is overjoyed to be reunited with their pet and thanks you profusely!"
            player.c.happiness += 20
            player.c.social += 15
        elif dilemma.answer == answerOptions[1]:
            message = "You post photos of the dog on social media. Within hours, the owners see your post and come to pick up their beloved pet. They're so grateful!"
            player.c.happiness += 10
            player.c.social += 10
        elif dilemma.answer == answerOptions[2]:
            message = "You decide to keep the dog. It's adorable and friendly, but you can't shake the feeling that somewhere, a family is heartbroken looking for their pet."
            player.c.happiness += 30
            player.c.social -= 20
        elif dilemma.answer == answerOptions[3]:
            message = "You leave the dog and walk away. You hope it finds its way home, but you wonder if you should have done more."
            player.c.happiness -= 10

        player.messageQueue.append(message)
        player.activeDilemmas.remove(dilemma)


def friendCheating(player, type='message', message=False, response=False, dilemma=False):
    """Friend cheating on partner dilemma"""
    fname = 'friendCheating'
    check = fname not in player.askedQuestions and player.c.ageYears >= 16 and 1 >= random.random()*1000

    answerOptions = [
        answerOption('Tell the partner', energyCost=10),
        answerOption('Confront your friend', energyCost=15),
        answerOption('Stay out of it'),
        answerOption('Support your friend regardless')
    ]

    if (check and type != 'answer'):
        from functions import get_random_friend
        friend = get_random_friend(player)
        if (friend):
            dilemma = dilemmaClass(fname, answerOptions)
            dilemma.friend = friend.id
            player.activeDilemmas.append(dilemma)
            message = f"You discover that your friend {friend.firstname} {friend.lastname} is cheating on their partner. What do you do?"
            return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        player.activeDilemmas[-1].answer = next((option for option in answerOptions if option.option == response['option']), None)
        player.c.energy -= player.activeDilemmas[-1].answer.energyCost
    elif dilemma and hasattr(dilemma, 'step') and hasattr(dilemma, 'answer') and dilemma.step == 2:
        from functions import get_person
        friend = get_person(player, dilemma.friend)
        message = ""

        if dilemma.answer == answerOptions[0]:
            message = f"You tell {friend.firstname}'s partner about the cheating. They're devastated but grateful you told them. {friend.firstname} is furious with you and your friendship is severely damaged."
            friend.affinity -= 30
            player.c.social -= 10
        elif dilemma.answer == answerOptions[1]:
            message = f"You confront {friend.firstname} about the cheating. They're defensive but eventually admit they need to make a choice. Your friendship is strained."
            friend.affinity -= 10
        elif dilemma.answer == answerOptions[2]:
            message = f"You decide to stay out of it. It's not your place to get involved. But you feel guilty every time you see {friend.firstname} and their partner together."
            player.c.happiness -= 10
        elif dilemma.answer == answerOptions[3]:
            message = f"You support {friend.firstname} no matter what. They appreciate your loyalty, but you feel uncomfortable condoning their behavior."
            friend.affinity += 10
            player.c.happiness -= 15

        player.messageQueue.append(message)
        player.activeDilemmas.remove(dilemma)


def foundExpensiveItem(player, type='message', message=False, response=False, dilemma=False):
    """Finding expensive item in store dilemma"""
    fname = 'foundExpensiveItem'
    check = fname not in player.askedQuestions and player.c.ageYears >= 10 and 1 >= random.random()*1000

    answerOptions = [
        answerOption('Turn it in to store'),
        answerOption('Look for owner yourself', energyCost=20),
        answerOption('Keep it'),
        answerOption('Leave it where it is')
    ]

    if (check and type != 'answer'):
        message = "You find an expensive phone in a store. What do you do?"
        dilemma = dilemmaClass(fname, answerOptions)
        player.activeDilemmas.append(dilemma)
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        player.activeDilemmas[-1].answer = next((option for option in answerOptions if option.option == response['option']), None)
        player.c.energy -= player.activeDilemmas[-1].answer.energyCost
    elif dilemma and hasattr(dilemma, 'step') and hasattr(dilemma, 'answer') and dilemma.step == 2:
        message = ""

        if dilemma.answer == answerOptions[0]:
            message = "You turn the phone in to the store's lost and found. A week later, the owner contacts you to thank you and gives you a $50 reward for your honesty!"
            player.c.happiness += 15
            player.c.social += 20
            player.c.money += 50
            player.c.diamonds += 10
        elif dilemma.answer == answerOptions[1]:
            message = "You look through the phone to find the owner's contact info and call them. They're incredibly grateful and meet you to get it back. It feels good to help someone."
            player.c.happiness += 25
        elif dilemma.answer == answerOptions[2]:
            message = "You keep the phone. It's nice, but you feel guilty every time you use it, wondering who you took it from."
            player.c.happiness -= 30
            player.c.money += 200
        elif dilemma.answer == answerOptions[3]:
            message = "You leave it where it is. Maybe the owner will come back for it. You hope they find it."
            player.c.happiness -= 5

        player.messageQueue.append(message)
        player.activeDilemmas.remove(dilemma)


def colleagueStealingCredit(player, type='message', message=False, response=False, dilemma=False):
    """Coworker taking credit for your work dilemma"""
    fname = 'colleagueStealingCredit'
    check = fname not in player.askedQuestions and player.c.ageYears >= 22 and player.c.ageYears <= 65 and player.c.occupation == 'work' and 1 >= random.random()*1000

    answerOptions = [
        answerOption('Call them out publicly'),
        answerOption('Talk to them privately', energyCost=10),
        answerOption('Tell your boss'),
        answerOption('Let it go')
    ]

    if (check and type != 'answer'):
        message = "A coworker presented your idea as their own in a meeting. How do you respond?"
        dilemma = dilemmaClass(fname, answerOptions)
        player.activeDilemmas.append(dilemma)
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        player.activeDilemmas[-1].answer = next((option for option in answerOptions if option.option == response['option']), None)
        player.c.energy -= player.activeDilemmas[-1].answer.energyCost
    elif dilemma and hasattr(dilemma, 'step') and hasattr(dilemma, 'answer') and dilemma.step == 2:
        message = ""

        if dilemma.answer == answerOptions[0]:
            message = "You call out your coworker in front of everyone. The room gets awkward. Your boss looks uncomfortable. You're right, but you've made an enemy."
            player.c.happiness += 10
            player.c.social -= 20
        elif dilemma.answer == answerOptions[1]:
            message = "You pull your coworker aside and tell them you know what happened. They apologize and agree to set the record straight. Your boss later acknowledges your contribution."
            player.c.social += 5
            player.c.happiness += 10
        elif dilemma.answer == answerOptions[2]:
            message = "You tell your boss privately that it was your idea. They investigate and confirm it. Your coworker is reprimanded, and your boss knows they can trust you."
            player.c.social -= 10
            player.c.happiness += 15
        elif dilemma.answer == answerOptions[3]:
            message = "You let it go. It eats at you, but you decide it's not worth the conflict. Your coworker gets praised for 'their' work."
            player.c.happiness -= 20
            player.c.social -= 5

        player.messageQueue.append(message)
        player.activeDilemmas.remove(dilemma)


def strayAnimalDecision(player, type='message', message=False, response=False, dilemma=False):
    """Stray animal needs help dilemma"""
    fname = 'strayAnimalDecision'
    check = fname not in player.askedQuestions and player.c.ageYears >= 10 and 1 >= random.random()*1000

    answerOptions = [
        answerOption('Adopt it', moneyCost=200, energyCost=15),
        answerOption('Take to shelter', energyCost=10),
        answerOption('Feed it but leave it', moneyCost=50),
        answerOption('Nothing')
    ]

    if (check and type != 'answer'):
        animal = random.choice(['cat', 'dog'])
        message = f"There's a skinny stray {animal} in your neighborhood. It looks hungry and sad. What do you do?"
        dilemma = dilemmaClass(fname, answerOptions)
        dilemma.animal = animal
        player.activeDilemmas.append(dilemma)
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        player.activeDilemmas[-1].answer = next((option for option in answerOptions if option.option == response['option']), None)
        player.c.energy -= player.activeDilemmas[-1].answer.energyCost
        player.c.money -= player.activeDilemmas[-1].answer.moneyCost
    elif dilemma and hasattr(dilemma, 'step') and hasattr(dilemma, 'answer') and dilemma.step == 2:
        animal = dilemma.animal if hasattr(dilemma, 'animal') else 'animal'
        message = ""

        if dilemma.answer == answerOptions[0]:
            message = f"You adopt the {animal}! It takes some time and money to get them healthy, but they become a loving companion. Your life is enriched by their presence."
            player.c.happiness += 30
        elif dilemma.answer == answerOptions[1]:
            message = f"You take the {animal} to a shelter where they can get proper care and hopefully find a home. It's the responsible choice."
            player.c.happiness += 15
        elif dilemma.answer == answerOptions[2]:
            message = f"You start feeding the {animal} regularly. They're healthier now, but you wonder if they'd be better off in a real home."
            player.c.happiness += 10
        elif dilemma.answer == answerOptions[3]:
            message = f"You do nothing. You see the {animal} around sometimes, still looking thin and sad. You feel guilty."
            player.c.happiness -= 10

        player.messageQueue.append(message)
        player.activeDilemmas.remove(dilemma)


def witnessShoplifting(player, type='message', message=False, response=False, dilemma=False):
    """Witnessing someone shoplift dilemma"""
    fname = 'witnessShoplifting'
    check = fname not in player.askedQuestions and player.c.ageYears >= 12 and 1 >= random.random()*1000

    answerOptions = [
        answerOption('Tell store employee'),
        answerOption('Offer to buy them food', moneyCost=20, diamondCost=5),
        answerOption('Look the other way'),
        answerOption('Talk to them about it', energyCost=10)
    ]

    if (check and type != 'answer'):
        message = "You see a teen shoplifting food from a grocery store. They look hungry. What do you do?"
        dilemma = dilemmaClass(fname, answerOptions)
        player.activeDilemmas.append(dilemma)
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        player.activeDilemmas[-1].answer = next((option for option in answerOptions if option.option == response['option']), None)
        player.c.energy -= player.activeDilemmas[-1].answer.energyCost
        player.c.money -= player.activeDilemmas[-1].answer.moneyCost
        player.c.diamonds -= player.activeDilemmas[-1].answer.diamondCost
    elif dilemma and hasattr(dilemma, 'step') and hasattr(dilemma, 'answer') and dilemma.step == 2:
        message = ""

        if dilemma.answer == answerOptions[0]:
            message = "You tell a store employee. They confront the teen, who looks scared and embarrassed. You followed the rules, but you feel bad."
            player.c.social -= 10
            player.c.happiness -= 5
        elif dilemma.answer == answerOptions[1]:
            message = "You approach the teen and offer to buy them food. They're surprised but grateful. They explain they're going through a hard time. You help them find resources for assistance."
            player.c.happiness += 25
            player.c.social += 10
        elif dilemma.answer == answerOptions[2]:
            message = "You look away and pretend you didn't see anything. You understand that sometimes people are desperate."
            player.c.happiness -= 5
        elif dilemma.answer == answerOptions[3]:
            message = "You talk to them about their situation. They open up about their struggles, and you help direct them to food banks and support services."
            player.c.happiness += 15
            player.c.social += 10

        player.messageQueue.append(message)
        player.activeDilemmas.remove(dilemma)


def friendBorrowMoney(player, type='message', message=False, response=False, dilemma=False):
    """Friend asks to borrow significant money dilemma"""
    fname = 'friendBorrowMoney'
    check = fname not in player.askedQuestions and player.c.ageYears >= 18 and player.c.money >= 500 and 1 >= random.random()*1000

    answerOptions = [
        answerOption('Yes, give them money', moneyCost=500),
        answerOption('Yes, but make contract', moneyCost=500, diamondCost=5),
        answerOption('Offer smaller amount', moneyCost=100),
        answerOption('Say no')
    ]

    if (check and type != 'answer'):
        from functions import get_random_friend
        friend = get_random_friend(player)
        if (friend):
            dilemma = dilemmaClass(fname, answerOptions)
            dilemma.friend = friend.id
            player.activeDilemmas.append(dilemma)
            message = f"Your friend {friend.firstname} {friend.lastname} asks to borrow $500. They're in a tough spot. Do you lend it?"
            return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        player.activeDilemmas[-1].answer = next((option for option in answerOptions if option.option == response['option']), None)
        player.c.energy -= player.activeDilemmas[-1].answer.energyCost
        player.c.money -= player.activeDilemmas[-1].answer.moneyCost
        player.c.diamonds -= player.activeDilemmas[-1].answer.diamondCost
    elif dilemma and hasattr(dilemma, 'step') and hasattr(dilemma, 'answer') and dilemma.step == 2:
        from functions import get_person
        friend = get_person(player, dilemma.friend)
        message = ""
        repayChance = random.random()

        if dilemma.answer == answerOptions[0]:
            if repayChance > 0.5:
                message = f"{friend.firstname} pays you back a few months later. They're grateful for your help and your friendship is stronger."
                player.c.money += 500
                friend.affinity += 20
            else:
                message = f"Months pass and {friend.firstname} hasn't paid you back. You're too uncomfortable to bring it up. Your friendship feels strained."
                friend.affinity -= 10
                player.c.happiness -= 10
        elif dilemma.answer == answerOptions[1]:
            message = f"{friend.firstname} agrees to sign a simple contract. They pay you back on schedule. Your friendship remains strong and the professionalism helped."
            player.c.money += 500
            friend.affinity += 10
        elif dilemma.answer == answerOptions[2]:
            message = f"You give {friend.firstname} $100. It's not what they needed, but they appreciate the help. They seem disappointed but understanding."
            friend.affinity += 10
            player.c.happiness -= 5
        elif dilemma.answer == answerOptions[3]:
            message = f"You tell {friend.firstname} you can't lend them money. They're disappointed and the friendship feels awkward now."
            friend.affinity -= 15
            player.c.happiness -= 10

        player.messageQueue.append(message)
        player.activeDilemmas.remove(dilemma)


def environmentalChoice(player, type='message', message=False, response=False, dilemma=False):
    """Choosing between convenience and environment dilemma"""
    fname = 'environmentalChoice'
    check = fname not in player.askedQuestions and player.c.ageYears >= 16 and 1 >= random.random()*1000

    answerOptions = [
        answerOption('Cheap flight', moneyCost=200, energyCost=30),
        answerOption('Eco-friendly option', moneyCost=400),
        answerOption("Don't fly at all"),
        answerOption('Train/bus instead', moneyCost=150, energyCost=40)
    ]

    if (check and type != 'answer'):
        message = "You need to travel across the country. You can take a cheap flight with multiple connections or pay more for a direct eco-friendlier option. What do you choose?"
        dilemma = dilemmaClass(fname, answerOptions)
        player.activeDilemmas.append(dilemma)
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        player.activeDilemmas[-1].answer = next((option for option in answerOptions if option.option == response['option']), None)
        player.c.energy -= player.activeDilemmas[-1].answer.energyCost
        player.c.money -= player.activeDilemmas[-1].answer.moneyCost
    elif dilemma and hasattr(dilemma, 'step') and hasattr(dilemma, 'answer') and dilemma.step == 2:
        message = ""

        if dilemma.answer == answerOptions[0]:
            message = "You take the cheap flight with multiple layovers. It's exhausting and takes all day, but you saved money. You try not to think about the carbon footprint."
            player.c.happiness -= 5
        elif dilemma.answer == answerOptions[1]:
            message = "You pay extra for the more efficient direct flight. It costs more, but you feel good about making a more environmentally conscious choice."
            player.c.happiness += 15
        elif dilemma.answer == answerOptions[2]:
            message = "You decide not to make the trip at all. It's disappointing, but you feel you made the right environmental choice."
            player.c.happiness -= 10
            player.c.social -= 10
        elif dilemma.answer == answerOptions[3]:
            message = "You take a train instead. It takes much longer and you're exhausted, but you enjoyed seeing the countryside and feel good about the lower environmental impact."
            player.c.happiness += 10

        player.messageQueue.append(message)
        player.activeDilemmas.remove(dilemma)


def parentCareDecision(player, type='message', message=False, response=False, dilemma=False):
    """Deciding on care for aging parent dilemma"""
    fname = 'parentCareDecision'
    check = fname not in player.askedQuestions and player.c.ageYears >= 40 and player.c.ageYears <= 70 and 1 >= random.random()*1000

    answerOptions = [
        answerOption('Nursing home', moneyCost=3000),
        answerOption('Live with you', moneyCost=500, energyCost=30),
        answerOption('Hire in-home care', moneyCost=2000),
        answerOption('Rely on siblings')
    ]

    if (check and type != 'answer'):
        parent_type = random.choice(['mother', 'father'])
        message = f"Your {parent_type} can no longer live alone safely. What's the best option?"
        dilemma = dilemmaClass(fname, answerOptions)
        dilemma.parent_type = parent_type
        player.activeDilemmas.append(dilemma)
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        player.activeDilemmas[-1].answer = next((option for option in answerOptions if option.option == response['option']), None)
        player.c.energy -= player.activeDilemmas[-1].answer.energyCost
        player.c.money -= player.activeDilemmas[-1].answer.moneyCost
    elif dilemma and hasattr(dilemma, 'step') and hasattr(dilemma, 'answer') and dilemma.step == 2:
        parent_type = dilemma.parent_type if hasattr(dilemma, 'parent_type') else 'parent'
        message = ""

        if dilemma.answer == answerOptions[0]:
            message = f"You move your {parent_type} into a nursing home. They're well cared for, but you feel guilty every time you visit. They seem sad but understanding."
            player.c.happiness -= 20
        elif dilemma.answer == answerOptions[1]:
            message = f"Your {parent_type} moves in with you. It's challenging and exhausting, but you get to spend quality time together. They're grateful and you have no regrets."
            player.c.happiness += 10
        elif dilemma.answer == answerOptions[2]:
            message = f"You hire in-home care for your {parent_type}. They can stay in their home with professional help. It's expensive but feels like the right balance."
            player.c.happiness += 5
        elif dilemma.answer == answerOptions[3]:
            message = f"You arrange for your siblings to share care responsibilities. But they feel you're not doing your part, and family tensions increase."
            player.c.happiness -= 15
            player.c.social -= 15

        player.messageQueue.append(message)
        player.activeDilemmas.remove(dilemma)


def whistleblowerDecision(player, type='message', message=False, response=False, dilemma=False):
    """Discovering unethical behavior at work dilemma"""
    fname = 'whistleblowerDecision'
    check = fname not in player.askedQuestions and player.c.ageYears >= 25 and player.c.ageYears <= 65 and player.c.occupation == 'work' and 1 >= random.random()*1000

    answerOptions = [
        answerOption('Report to authorities', diamondCost=20),
        answerOption('Report internally'),
        answerOption('Look for new job first', energyCost=30),
        answerOption('Stay silent', moneyCost=-500)
    ]

    if (check and type != 'answer'):
        message = "You discover your company is doing something unethical. Report it?"
        dilemma = dilemmaClass(fname, answerOptions)
        player.activeDilemmas.append(dilemma)
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        player.activeDilemmas[-1].answer = next((option for option in answerOptions if option.option == response['option']), None)
        player.c.energy -= player.activeDilemmas[-1].answer.energyCost
        player.c.diamonds -= player.activeDilemmas[-1].answer.diamondCost
        if player.activeDilemmas[-1].answer.moneyCost < 0:
            player.c.money += abs(player.activeDilemmas[-1].answer.moneyCost)
    elif dilemma and hasattr(dilemma, 'step') and hasattr(dilemma, 'answer') and dilemma.step == 2:
        message = ""

        if dilemma.answer == answerOptions[0]:
            outcome = random.random()
            if outcome > 0.5:
                message = "You report to authorities. There's an investigation and the company is held accountable. You lose your job but you're protected as a whistleblower and find a better position. You did the right thing."
                player.c.happiness += 30
                player.c.occupation = 'unemployed'
            else:
                message = "You report to authorities but the investigation goes nowhere. Your company finds out it was you and you're quietly let go. It was the right thing to do, but it cost you."
                player.c.happiness += 20
                player.c.occupation = 'unemployed'
        elif dilemma.answer == answerOptions[1]:
            message = "You report internally through proper channels. The company addresses the issue quietly. You keep your job but you're watched closely now."
            player.c.happiness += 10
            player.c.social -= 10
        elif dilemma.answer == answerOptions[2]:
            message = "You start looking for a new job before saying anything. You find a position elsewhere and leave quietly. The unethical practices likely continue."
            player.c.happiness -= 10
        elif dilemma.answer == answerOptions[3]:
            message = "You stay silent and keep collecting your paycheck. You rationalize it, but the guilt weighs on you. You're complicit now."
            player.c.happiness -= 30

        player.messageQueue.append(message)
        player.activeDilemmas.remove(dilemma)


__all__ = [
    'bullyDilemma',
    'braceletDilemma',
    'foundLostPet',
    'friendCheating',
    'foundExpensiveItem',
    'colleagueStealingCredit',
    'strayAnimalDecision',
    'witnessShoplifting',
    'friendBorrowMoney',
    'environmentalChoice',
    'parentCareDecision',
    'whistleblowerDecision',
]
