"""
School Test and Exam Events
Standardized tests and exam preparation (ages 15-18)

Events:
- actTest: ACT test preparation
- actTestTake: Taking the ACT test
- satTest: SAT test preparation
"""

import random
from events.base import messageFunction, questionFunction


def actTest(player, type='message'):
    """ACT test preparation"""
    from functions import scheduler
    fname = 'actTest'
    check = player.c.education == "12th" and player.monthOfYear > 9 and player.c.ageYears >= 16 and player.c.ageYears < 19 and fname not in player.events and  'school' in player.c.location
    message = "Your guidance counselor reminds you of the upcoming ACT test. It's time to get studying!"
    if (check):
        player.c.schedules.append(scheduler(player.c,"Studying for ACT",["twice-week","evening"],location="home"+player.c.id,duration=random.randint(20,50)))
    return messageFunction(fname,message,player,check)


def actTestTake(player, type='message', message=False, response=False, dilemma=False):
    """Taking the ACT test"""
    fname = 'actTestTake'
    from functions import scheduleComplete
    check = not player.c.actScore and scheduleComplete(player.c,'Studying for ACT')
    answerOptions = ["I've done all the studying I can."]
    if (type != "answer" and check):
        message = "Today is your ACT test!"
        return questionFunction(fname,message,player,check,answerOptions)
    if (type == 'answer'):
        # add the response to the dilemma in player.activeDilemmas
        message = ""
        if (random.random() >= 0.5):
            message = "You did well!"
            player.c.actScore = random.randint(20,36)
        else:
            message = "You did not do well."
            player.c.actScore = random.randint(10,19)
        player.messageQueue.append(message)


def satTest(player, type='message'):
    """SAT test preparation"""
    from functions import scheduler
    fname = 'satTest'
    check = player.c.education == "12th" and player.dayOfYear == 1 and player.c.ageYears >= 17 and player.c.ageYears < 19 and fname not in player.events and  'school' in player.c.location
    message = "Your guidance counselor reminds you of the upcoming SAT test. It's time to get studying!"
    if (check):
        player.c.schedules.append(scheduler(player.c,"Studying for SAT",["twice-week","evening"],location="home"+player.c.id,duration=random.randint(20,50)))
    return messageFunction(fname,message,player,check)


__all__ = [
    'actTest',
    'actTestTake',
    'satTest',
]
