"""
Career and Employment Events
Jobs, work, and career progression (ages 15+)

Events:
- firstJob: First part-time job
- jobApplication: Applying for post-college jobs
- employeeOfTheMonth: Recognition at work
- openbankAccount: Opening a bank account
"""

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


def firstJob(player, type='message', message=False, response=False):
    """First part-time job"""
    fname = 'firstJob'
    check = fname not in player.askedQuestions and not player.c.job and player.c.ageYears >= 15 and player.c.ageYears < 18 and 1 >= random.random()*100000
    message = "You are now old enough for your first part-time job, what would you like to do?"
    if (type != 'answer'):
        if (check):
            answerOptions = []
            for occupation in player.occupations:
                if (occupation.requirements == 'none'):
                    answerOptions.append(occupation.title)
            return questionFunction(fname,message,player,check,answerOptions)
    elif(type == 'answer'):
        if (response['option'] != 'None'):
            for occupation in player.occupations:
                if (occupation.title == response['option']):
                    from functions import setJob
                    occupation.hourType = 'partTime'
                    setJob(player.c,occupation,player.date)
                    #create coworkers
                    from functions import create_coworkers
                    player = create_coworkers(player,occupation)


def jobApplication(player, type='message', message=False, response=False):
    """Applying for post-college jobs"""
    fname = 'jobApplication'
    check = fname not in player.askedQuestions and player.c.major and player.c.college and player.c.occupation == 'work' and not player.c.job and 1 >= random.random()*100

    if (type != 'answer' and check):
        message = "You have graduated from "+player.c.college.title+" and are now applying for jobs! What position would you like to apply for?"
        # find all jobs that are avaialbe for this major, and that the player has the requirements for found in player.majors and player.occupations
        cMajor = None
        for major in player.majors:
            if (major.id == player.c.major):
                cMajor = major
        if (cMajor):
            answerOptions = cMajor.related_jobs
            return questionFunction(fname,message,player,check,answerOptions)
    elif (type == 'answer'):
        if (response['option'] != 'None'):
            for occupation in player.occupations:
                if (occupation.title == response['option']):
                    from functions import setJob
                    setJob(player.c,occupation,player.date)
                    #create coworkers
                    from functions import create_coworkers
                    player = create_coworkers(player,occupation)


def employeeOfTheMonth(player, type='message'):
    """Recognition at work"""
    fname = 'employeeOfTheMonth'
    check = fname not in player.events and getattr(player.c,'job',False)
    if (check):
        for record in player.c.activityRecords:
            if (record.id == player.c.job.id):
                check = record.performance >= 50 and record.focus == "Word Hard"
                message = "You were named employee of the month"
                return messageFunction(fname,message,player,check)


def openbankAccount(player, type='message', message=False, response=False):
    """Opening a bank account"""
    fname ='openbankAccount'
    check = fname not in player.askedQuestions and player.c.ageYears >= 15 and player.c.ageYears <= 20 and 1 >=random.random()*1000
    message = "You're making real money now and the piggy bank isn't big enough anymore! Whats next?"
    answerOptions = [answerOption('Open a new account at the local bank',moneyCost=10),answerOption('Open a new account with a promotional bonus',diamondCost=10)] #would be cool to revist this and add a monetary qualifier for this option
    if (type != 'answer'):
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        if (response ['option'] == answerOptions[0]):
            player.messageQueue.append("You have a new bank account! Wait... since when did checks cost so much money? Whats the point?")
        elif (response ['option'] == answerOptions[1]):
            player.messageQueue.append("You have enough money to qualify for the new account promotional bonus, nice!")


__all__ = [
    'firstJob',
    'jobApplication',
    'employeeOfTheMonth',
    'openbankAccount',
]
