# pylint: disable=line-too-long
"""Functionality to inspect potions.
"""
import time


def inspection_by_snoope(potion, target_potion='python_expert'):  # pylint: disable=invalid-name
    """Checks if potion was brewed correctly.

    Prints narration of inspection process - read to see if potion passed inspection.
    Snoope checks container, heat_source, ingredients, and whether potion was cooked.
    If something is wrong, function returns at that point.

    Parameters
    ----------
    potion : obj 
        Instance of Potion (class from potion_class).
    target_potion: str, optional
        Name of potion to be checked by Snoope. Currently possible potions are 'python expert', 'example_potion'
    """

    print('-------------------------------')
    if not potion:
        print('"There is no potion I can inspect!" says Snoope and ignores you completely.')
        print('    (Tip: are you actually returning a proper potion and passing it to Snoope?)')
        return

    print(f'A sour looking Snoope walks towards you to inspect your {target_potion} potion.')
    print(f'"What do we have here, {potion.student_name}...?"')
    print_delay_dots()

    # set variables for each potion that need to be checked
    if target_potion == 'python_expert':
        expected_container = 'pewter_cauldron'
        expected_heat_source = 'fire'
    elif target_potion == 'example_potion':
        expected_container = 'old_kettle'
        expected_heat_source = 'eternal_flame'
    else:
        print(f'"What is this, {potion.student_name}? This is not the name of an existing potion, check your spelling!"')
        print('    (Target potion was not recognised, please check your spelling.)')
        return

    # check that correct setup was used
    if potion.container == expected_container and potion.heat_source == expected_heat_source:
        print('You have used the correct setup, Snoope cannot complain - he looks even more sour.')
    else:
        print(f'Snoope smirks and remarks "You have used the wrong cauldron or heat, {potion.student_name}!" \n'
              f'With a flick of his wand he vanishes the potion. \n'
              f'"I am taking 10 points from Ravenclaw, {potion.student_name}. Start again!"')
        return

    print_delay_dots()

        # set variables for each potion that need to be checked
    if target_potion == 'python_expert':
        expected_ingredients = ['fish_eyes', 'tea_leaves', 'unicorn_hair']
        expected_cooked = True
        expected_simmer_duration = 2
        expected_anticlock_colour = "newt-green"
        expected_clock_colour = "vomit-yellow"
    elif target_potion == 'example_potion':
        expected_ingredients = []
        expected_cooked = True
        expected_simmer_duration = 5
    else:
        print(f'"What is this, {potion.student_name}? This is not the name of an existing potion, check your spelling!"')
        print('    (Target potion name was not recognised, please check your spelling.)')
        return

    # check if all ingredients are there
    if sorted(potion.ingredients) == expected_ingredients:
        print('You have used the correct ingredients, Snoope cannot complain - his face darkens.')
    else:
        print(f'Snoope smirks and remarks "You have used the wrong ingredients, {potion.student_name}!" \n'
              f'With a flick of his wand he vanishes the potion. \n'
              f'"I am taking 10 points from Gryffindor, {potion.student_name}. Start again!"')
        return

    print_delay_dots()

    # check that potion is cooked
    if potion.cooked == expected_cooked and potion.simmer_duration == expected_simmer_duration:
        print('The potion is cooked properly, Snoope cannot complain - he is looking annyoyed now.')
    else:
        if potion.simmer_duration < expected_simmer_duration:
            print('Snoope smirks and remarks "Your potion is undercooked!" \n')
        elif potion.simmer_duration > expected_simmer_duration:
            print('Snoope smirks and remarks "Your potion is overcooked!" \n')
        print(f'With a flick of his wand he vanishes the potion. \n'
              f'"I am taking 10 points from Hufflepuff, {potion.student_name}. Start again!"')
        return

    print_delay_dots()

    if target_potion == 'python_expert' and potion.colour == expected_anticlock_colour:
        print("Professor Dimbledore unexpectedly walks through the door, sees your potion and exclaims:")
        print(f'"Oh my, {potion.student_name}, your potion is absolutely perfect! ')
        print('    You earn 1000 points and the House Cup for this year\'s ASPP Summer School!"')
        print('You and your class mates leave to have a butterbeer at the beach in Heraklion!')
    elif target_potion == 'python_expert' and potion.colour == expected_clock_colour:
        print("Your potion does not only look disgusting, it also smells like rotten eggs. ")
        print("You vomit into your cauldron and while this does not change the colour, you know you will not pass the class, so you start again. ")
    else:
        print(f'Snoope mutters "You got away this time, {potion.student_name}!", since there is nothing wrong with '
          f'your {target_potion} potion.')
        print_delay_dots()
        print('You pack your bags and leave as fast as you can to have a butterbeer at the beach in Heraklion!')

    return


def print_delay_dots(dur=0.5, number=2):
    """Print dots to screen during delay."""
    for _ in range(number):
        time.sleep(dur)
        print('.')
