"""
Positive Random Events
Lucky, positive surprise events

Events:
- foundAPenny: Finding a lucky penny
- freeConcert: Free concert tickets
- foundMoneyStreet: Finding money on the ground
- freeUpgrade: Unexpected upgrade or free item
- unexpectedCompliment: Stranger gives sincere compliment
- perfectParkingSpot: Finding the perfect parking spot
- rainbowSighting: Seeing a beautiful rainbow
"""

import random
from events.base import messageFunction, questionFunction


def foundAPenny(player, type='message', message=False, response=False):
    """Finding a lucky penny"""
    fname = 'foundAPenny'
    check = fname not in player.askedQuestions and player.c.ageYears > 5 and 1 >= random.random()*1000000
    message = "You see something shiny on the ground. Do you pick it up?"
    if (type != 'answer'):
        answerOptions = ['Pick it up', 'Leave it on the ground']
        return questionFunction(fname, message, player, check, answerOptions)
    elif (type == 'answer'):
        if (response ['option'] == 'Pick it up'):
            player.messageQueue.append('You pick up a penny. Find a penny, pick it up, all day long you\'ll have good luck!')
            player.c.money += 0.01
            player.c.happiness += 5


def freeConcert(player, type='message', message=False, response=False):
    """Free concert tickets"""
    fname = 'freeConcert'
    check = fname not in player.askedQuestions and player.c.ageYears >= 14 and player.c.ageYears < 100 and 1 >= random.random()*1000
    message = "Your favorite Band is coming to town and tickets are pricey. You see that there is an enter-to-win competition online. Do you want to enter?"
    if (type != 'answer'):
        return questionFunction(fname,message,player,check)
    elif (type == 'answer'):
        if(response ['option'] == 'Yes'):
            player.messageQueue.append('A day after entering the competition you receive a phone call from the concert venue confirming that you just won two tickets to see the band!')
            player.c.happiness += 10
        else:
            player.messageQueue.append('A week passes and you never hear if you won tickets. Oh well, perhaps next time!')


def foundMoneyStreet(player, type='message'):
    """Finding money on the ground"""
    fname = 'foundMoneyStreet'
    check = fname not in player.events and player.c.ageYears >= 8 and player.c.ageYears <= 100 and 1 >= random.random()*5000
    message = "You found a $20 bill on the sidewalk! Lucky day!"

    if check:
        player.events.add(fname)
        player.c.money += 20
        player.c.happiness += 10

    return messageFunction(fname, message, player, check)


def freeUpgrade(player, type='message'):
    """Unexpected upgrade or free item"""
    fname = 'freeUpgrade'
    check = fname not in player.events and player.c.ageYears >= 16 and player.c.ageYears <= 100 and 1 >= random.random()*8000

    # Random message options
    messages = [
        "The coffee shop gave you a free drink!",
        "Your flight got upgraded to first class!",
        "You won a raffle you forgot you entered!",
        "Your food order came with extra fries!"
    ]
    message = random.choice(messages)

    if check:
        player.events.add(fname)
        player.c.happiness += 15

    return messageFunction(fname, message, player, check)


def unexpectedCompliment(player, type='message'):
    """Stranger gives sincere compliment"""
    fname = 'unexpectedCompliment'
    check = fname not in player.events and player.c.ageYears >= 10 and player.c.ageYears <= 100 and 1 >= random.random()*6000
    message = "A stranger complimented you today. It really made your day!"

    if check:
        player.events.add(fname)
        player.c.happiness += 10
        player.c.social += 5

    return messageFunction(fname, message, player, check)


def perfectParkingSpot(player, type='message'):
    """Finding the perfect parking spot"""
    fname = 'perfectParkingSpot'
    check = fname not in player.events and player.c.ageYears >= 16 and player.c.ageYears <= 100 and player.c.canDrive and 1 >= random.random()*7000
    message = "Right as you arrived, someone pulled out of the perfect parking spot. It's the little things!"

    if check:
        player.events.add(fname)
        player.c.happiness += 5

    return messageFunction(fname, message, player, check)


def rainbowSighting(player, type='message'):
    """Seeing a beautiful rainbow"""
    fname = 'rainbowSighting'
    check = fname not in player.events and player.c.ageYears >= 3 and player.c.ageYears <= 100 and 1 >= random.random()*10000
    message = "You saw a beautiful double rainbow today. You stopped to appreciate it."

    if check:
        player.events.add(fname)
        player.c.happiness += 10

    return messageFunction(fname, message, player, check)


__all__ = [
    'foundAPenny',
    'freeConcert',
    'foundMoneyStreet',
    'freeUpgrade',
    'unexpectedCompliment',
    'perfectParkingSpot',
    'rainbowSighting',
]
