"""
Childhood Activity Events
Learning activities for young children (ages 2-12)

Events:
- learnedBike: Learning to ride a bike
- learnedSwim: Learning to swim
- childhoodActivity: General childhood activity selection
- learnInstrument: Learning a musical instrument
- playDate: Play date with another child
"""

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


def learnedBike(player, type='message'):
    from functions import scheduler
    fname = 'learnedBike'
    check = player.c.ageDays >= 720 and player.c.ageDays < 1460 and fname not in player.events and  'home' in player.c.location and 1 >= random.random()*1000
    message = "Your parents have decided to start teaching you to ride a bike."
    if (check):
        player.c.schedules.append(scheduler(player.c,"Learning to ride bike",["daily","evening"],location="home"+player.c.id,duration=random.randint(5,10)))
    return messageFunction(fname,message,player,check)


def learnedSwim(player, type='message'):
    from functions import scheduler
    fname = 'learnedSwim'
    check = player.c.ageDays >= 1460 and player.c.ageDays < 2190 and fname not in player.events and  'home' in player.c.location and 1 >= random.random()*1000
    message = "Your parents have signed you up for swimming lessons!"
    if (check):
        player.c.schedules.append(scheduler(player.c,"Learning to swim",["daily","evening"],location="home"+player.c.id,duration=random.randint(5,10)))
    return messageFunction(fname,message,player,check)


def childhoodActivity(player, type='message', message=False, response=False):
    """General childhood activity selection - disabled until extracurricular buildout is complete"""
    fname = 'childhoodActivity'
    check = False and fname not in player.askedQuestions and player.c.ageYears >= 8 and player.c.ageYears < 13 and 1 >= random.random()*1000
    message = "Your parents want you to take on a new activity, what would you like to learn?"
    if (type != 'answer'):
        answerOptions = ['Learn Instrument','Dance Class', 'Sports Team','None']
        return questionFunction(fname,message,player,check,answerOptions)
    elif(type == 'answer'):
        if (response['option'] != 'None'):
            class extracurricular:
                def __init__(self,title):
                    self.type = 'extracurricular'
                    self.title = title
                    self.energyModifier = 10
            choice = extracurricular(response)
            choice.title = ['option']
            player.c.activities.append(choice)


def learnInstrument(player, type='message', message=False, response=False):
    """Learn a musical instrument - disabled until extracurricular buildout is complete"""
    fname = 'learnInstrument'
    check = False and 'learnInstrument' not in player.askedQuestions and 'childhoodActivity' in player.askedQuestions and len(player.c.activities) == 0 and player.c.ageYears >= 10 and player.c.ageYears < 18 and 1 >= random.random()*1000
    message = "What instrument would you like to learn?"
    if (type != 'answer'):
        answerOptions = ['Piano','Guitar','Violin','Drums','None']
        return questionFunction(fname,message,player,check,answerOptions)
    elif(type == 'answer'):
            if (response['option'] != 'None'):
                class extracurricular:
                    def __init__(self,title):
                        self.type = 'extracurricular'
                        self.title = title
                        self.energyModifier = 10
                choice = extracurricular(response)
                player.c.activities.append(choice)


def playDate(player, type='message', message=False, response=False):
    """Play date with another child"""
    fname = 'playDate'
    message = "Your parents have arranged a play date for you with another kid, how does it go?"
    answerOptions = ['It goes well',answerOption("You can't wait to hang out again!",diamondCost=3),'You and them do not get along.']
    check = fname not in player.askedQuestions and player.c.ageYears >= 4 and player.c.ageYears < 8 and 1 >= random.random()*100
    if (type != 'answer'):
        # NEW: Include player character avatar and playground location image
        return questionFunction(
            fname,
            message,
            player,
            check,
            answerOptions,
            characters=[player.c],  # Show player avatar
            image="https://images.unsplash.com/photo-1578328819058-b69f3a3b0f6b?w=800"  # Playground image
        )
    elif(type == 'answer'):
        if (response['option'] == answerOptions[0]):
            from app import add_friend
            player = add_friend(player,player.c.sex,'similar')
            player.messageQueue.append("You have made a new friend!")
        if (response['option'] == answerOptions[1]):
            from app import add_friend
            player = add_friend(player,player.c.sex,'similar')
            player.social += 10
            player.messageQueue.append("You love making friends!")
        else:
            player.social -= 10
            player.messageQueue.append("Your playdate did not go well")


__all__ = [
    'learnedBike',
    'learnedSwim',
    'childhoodActivity',
    'learnInstrument',
    'playDate',
]
