"""
Early Childhood Events
Emotional and social development events for young children (ages 2-7)

Events:
- firstDayOfPreschool: Emotional reaction to first day of preschool/daycare (ages 3-4, questionEvent)
- imaginaryFriend: Creating an imaginary friend (ages 3-5, questionEvent)
- firstNightmare: Waking up from a scary dream (ages 3-6, messageEvent)
- petGoldfish: Getting a first pet goldfish (ages 4-7, questionEvent)
- scaredOfDark: Fear of the dark at bedtime (ages 4-6, questionEvent)
- firstTimeTyingShoes: Learning to tie shoelaces (ages 5-7, messageEvent)
- sandboxDisagreement: Conflict over toys in sandbox/playground (ages 3-5, questionEvent)
- pickySomeEater: Going through a picky eating phase (ages 2-4, messageEvent)
- firstHaircut: Reaction to first haircut (ages 2-4, questionEvent)
"""

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


def firstDayOfPreschool(player, type='message', message=False, response=False):
    """Emotional reaction to first day of preschool/daycare (ages 3-4)"""
    fname = 'firstDayOfPreschool'
    check = fname not in player.askedQuestions and player.c.ageYears >= 3 and player.c.ageYears <= 4 and 1 >= random.random()*500
    message = "It's your first day of preschool! How do you feel about leaving your parents?"
    answerOptions = [
        'Cry and cling to parent',
        'Wave goodbye excitedly!',
        'Hide behind parent\'s leg'
    ]

    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif(type == 'answer'):
        if (response['option'] == answerOptions[0]):
            player.c.happiness -= 5
            player.c.energy -= 5
            player.messageQueue.append("You cried and didn't want your parents to leave, but eventually you calmed down.")
        elif (response['option'] == answerOptions[1]):
            player.c.happiness += 5
            player.c.social += 5
            player.messageQueue.append("You were excited to make new friends and explore!")
        else:
            player.c.happiness -= 3
            player.messageQueue.append("You were shy at first, but soon warmed up to your new environment.")


def imaginaryFriend(player, type='message', message=False, response=False):
    """Creating an imaginary friend (ages 3-5)"""
    fname = 'imaginaryFriend'
    check = fname not in player.askedQuestions and player.c.ageYears >= 3 and player.c.ageYears <= 5 and 1 >= random.random()*500
    message = "You've created an imaginary friend! What's their name?"
    answerOptions = [
        'Mr. Whiskers',
        'Rainbow',
        'Shadow',
        'I don\'t need imaginary friends'
    ]

    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif(type == 'answer'):
        if (response['option'] == answerOptions[0]):
            player.c.happiness += 10
            player.messageQueue.append("Mr. Whiskers becomes your constant companion in all your adventures!")
        elif (response['option'] == answerOptions[1]):
            player.c.happiness += 10
            player.c.social += 5
            player.messageQueue.append("Rainbow is your colorful friend who makes everything more fun!")
        elif (response['option'] == answerOptions[2]):
            player.c.happiness += 10
            player.messageQueue.append("Shadow follows you everywhere and keeps you company!")
        else:
            player.c.social -= 5
            player.messageQueue.append("You prefer to play with real friends instead.")


def firstNightmare(player, type='message'):
    """Waking up from a scary dream (ages 3-6)"""
    fname = 'firstNightmare'
    check = fname not in player.events and player.c.ageYears >= 3 and player.c.ageYears <= 6 and 1 >= random.random()*500
    message = "You woke up crying from a bad dream. Your parents comfort you and leave a nightlight on. You feel safe again."
    return messageFunction(fname, message, player, check)


def petGoldfish(player, type='message', message=False, response=False):
    """Getting a first pet goldfish (ages 4-7)"""
    fname = 'petGoldfish'
    check = fname not in player.askedQuestions and player.c.ageYears >= 4 and player.c.ageYears <= 7 and 1 >= random.random()*500
    message = "Your parents got you a goldfish! What do you name it?"
    answerOptions = [
        'Bubbles',
        'Nemo',
        answerOption('Sir Swimsalot', diamondCost=3),
        'Goldie'
    ]

    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif(type == 'answer'):
        if (response['option'] == answerOptions[0]):
            player.c.happiness += 10
            player.messageQueue.append("Bubbles swims happily in their new home!")
        elif (response['option'] == answerOptions[1]):
            player.c.happiness += 10
            player.messageQueue.append("Just like the movie! You love watching Nemo swim around.")
        elif (response['option'] == answerOptions[2].option):
            player.c.happiness += 15
            player.messageQueue.append("Sir Swimsalot is the most distinguished fish in all the land!")
        else:
            player.c.happiness += 10
            player.messageQueue.append("Goldie becomes your first pet and you take good care of them!")


def scaredOfDark(player, type='message', message=False, response=False):
    """Fear of the dark at bedtime (ages 4-6)"""
    fname = 'scaredOfDark'
    check = fname not in player.askedQuestions and player.c.ageYears >= 4 and player.c.ageYears <= 6 and 1 >= random.random()*500
    message = "You're scared of the dark. What helps you feel brave?"
    answerOptions = [
        'Ask for a nightlight',
        'Sleep with stuffed animal',
        answerOption('Check under the bed', energyCost=10),
        'Call for parent'
    ]

    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif(type == 'answer'):
        if (response['option'] == answerOptions[0]):
            player.c.happiness += 5
            player.c.energy += 5
            player.messageQueue.append("The soft glow of the nightlight makes you feel safe and you sleep peacefully.")
        elif (response['option'] == answerOptions[1]):
            player.c.happiness += 10
            player.messageQueue.append("Your favorite stuffed animal keeps you company and protects you from bad dreams!")
        elif (response['option'] == answerOptions[2].option):
            player.messageQueue.append("You bravely check under the bed. Nothing there! You feel proud of yourself.")
        else:
            player.c.happiness += 5
            player.messageQueue.append("Your parent reassures you that everything is okay and you drift off to sleep.")


def firstTimeTyingShoes(player, type='message'):
    """Learning to tie shoelaces (ages 5-7)"""
    fname = 'firstTimeTyingShoes'
    check = fname not in player.events and player.c.ageYears >= 5 and player.c.ageYears <= 7 and 1 >= random.random()*500
    message = "After many attempts, you finally tied your shoes by yourself! You feel so grown up."
    return messageFunction(fname, message, player, check)


def sandboxDisagreement(player, type='message', message=False, response=False):
    """Conflict over toys in sandbox/playground (ages 3-5)"""
    fname = 'sandboxDisagreement'
    check = fname not in player.askedQuestions and player.c.ageYears >= 3 and player.c.ageYears <= 5 and 1 >= random.random()*500
    message = "Another kid grabs the toy you were playing with. What do you do?"
    answerOptions = [
        'Grab it back!',
        'Tell a grown-up',
        'Find a different toy',
        answerOption('Suggest taking turns', diamondCost=5)
    ]

    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif(type == 'answer'):
        if (response['option'] == answerOptions[0]):
            player.c.social -= 5
            player.c.happiness += 5
            player.messageQueue.append("You grabbed it back! The other kid starts crying and you get in trouble.")
        elif (response['option'] == answerOptions[1]):
            player.c.social += 5
            player.messageQueue.append("The grown-up helps you both learn to share nicely.")
        elif (response['option'] == answerOptions[2]):
            player.c.happiness -= 5
            player.c.social += 5
            player.messageQueue.append("You're disappointed, but you find another fun toy to play with instead.")
        else:
            player.c.social += 15
            player.messageQueue.append("You both take turns! Great job sharing and making a new friend!")


def pickySomeEater(player, type='message'):
    """Going through a picky eating phase (ages 2-4)"""
    fname = 'pickySomeEater'
    check = fname not in player.events and player.c.ageYears >= 2 and player.c.ageYears <= 4 and 1 >= random.random()*500
    message = "You refuse to eat anything except chicken nuggets and mac & cheese. Your parents sigh and hope it's just a phase."
    return messageFunction(fname, message, player, check)


def firstHaircut(player, type='message', message=False, response=False):
    """Reaction to first haircut (ages 2-4)"""
    fname = 'firstHaircut'
    check = fname not in player.askedQuestions and player.c.ageYears >= 2 and player.c.ageYears <= 4 and 1 >= random.random()*500
    message = "It's time for your first haircut! How does it go?"
    answerOptions = [
        'Cry the whole time',
        'Sit very still and brave',
        answerOption('Can\'t stop wiggling', energyCost=5)
    ]

    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif(type == 'answer'):
        if (response['option'] == answerOptions[0]):
            player.c.happiness -= 10
            player.c.energy -= 5
            player.messageQueue.append("You cried through the whole haircut! At least it's over now.")
        elif (response['option'] == answerOptions[1]):
            player.c.happiness += 10
            player.messageQueue.append("You sat so still! The hairdresser said you were the best customer ever!")
        else:
            player.c.happiness += 5
            player.messageQueue.append("You couldn't help wiggling around! The haircut is a little uneven but still looks cute.")


__all__ = [
    'firstDayOfPreschool',
    'imaginaryFriend',
    'firstNightmare',
    'petGoldfish',
    'scaredOfDark',
    'firstTimeTyingShoes',
    'sandboxDisagreement',
    'pickySomeEater',
    'firstHaircut',
]
