"""
Childhood Milestone Events
Major developmental milestones for young children (ages 0-5)

Events:
- learnedWalk: Learning to walk (9-24 months)
- learnedTalk: Learning to talk (placeholder, not implemented)
- learningColors: Learning to identify colors (ages 2-3)
- lostFirstTooth: Losing first baby tooth (ages 6-8)
- lostLastTooth: Losing last baby tooth (ages 10-12)
"""

import random
import math
from events.base import messageFunction


def learnedWalk(player, type='message'):
    fname = 'learnedWalk'
    check = fname not in player.events and player.c.ageDays >= 270 and player.c.ageDays < 720 and 1 >= random.random()*1000
    message = "You have learned to walk at "+str(math.floor(player.c.ageDays / 7 / 4.35))+" months"
    return messageFunction(fname,message,player,check)


def lostFirstTooth(player, type='message'):
    fname = 'lostFirstTooth'
    check = player.c.ageYears >= 6 and player.c.ageYears <= 8 and fname not in player.events and 1 >= random.random()*1000
    message = "You have lost your first baby tooth!"
    return messageFunction(fname,message,player,check)


def lostLastTooth(player, type='message'):
    fname = 'lostLastTooth'
    check = player.c.ageYears >= 10 and player.c.ageYears <= 12 and fname not in player.events and 1 >= random.random()*1000
    message = "You have lost your last baby tooth!"
    return messageFunction(fname,message,player,check)


def learningColors(player, type='message'):
    """Learning to identify colors (ages 2-3)"""
    fname = 'learningColors'
    check = player.c.ageYears >= 2 and player.c.ageYears <= 3 and fname not in player.events and 1 >= random.random()*1000
    message = "You learned all your colors today! You can't stop pointing at things and naming them: Red truck! Blue sky! Yellow flower!"
    return messageFunction(fname, message, player, check)


def childLearnedWalk(player, type='message'):
    """Event for when player's child learns to walk"""
    fname = 'childLearnedWalk'

    check = getattr(player.c,'children',False)
    if (check):
        from functions import get_youngestChild
        child = get_youngestChild(player)
        check = fname not in player.events and child.ageDays >= 270 and child.ageDays < 720 and 1 >= random.random()*1000
        message = "Your child "+child.firstname+" learned to walk at "+str(math.floor(player.c.ageDays / 7 / 4.35))+" months"
        return messageFunction(fname,message,player,check)


__all__ = [
    'learnedWalk',
    'lostFirstTooth',
    'lostLastTooth',
    'learningColors',
    'childLearnedWalk',
]
