from typing import Dict
from typing import Optional


def get_exif_flash_fired(exif_data: Dict) -> Optional[bool]:
    """
    Parses the "flash" value from exif do determine if it was fired.

    Possible values:
    +-------------------------------------------------------+------+----------+-------+
    |                        Status                         | Hex  |  Binary  | Fired |
    +-------------------------------------------------------+------+----------+-------+
    | No Flash                                              | 0x0  | 00000000 | No    |
    | Fired                                                 | 0x1  | 00000001 | Yes   |
    | "Fired, Return not detected"                          | 0x5  | 00000101 | Yes   |
    | "Fired, Return detected"                              | 0x7  | 00000111 | Yes   |
    | "On, Did not fire"                                    | 0x8  | 00001000 | No    |
    | "On, Fired"                                           | 0x9  | 00001001 | Yes   |
    | "On, Return not detected"                             | 0xd  | 00001011 | Yes   |
    | "On, Return detected"                                 | 0xf  | 00001111 | Yes   |
    | "Off, Did not fire"                                   | 0x10 | 00010000 | No    |
    | "Off, Did not fire, Return not detected"              | 0x14 | 00010100 | No    |
    | "Auto, Did not fire"                                  | 0x18 | 00011000 | No    |
    | "Auto, Fired"                                         | 0x19 | 00011001 | Yes   |
    | "Auto, Fired, Return not detected"                    | 0x1d | 00011101 | Yes   |
    | "Auto, Fired, Return detected"                        | 0x1f | 00011111 | Yes   |
    |  No flash function                                    | 0x20 | 00100000 | No    |
    | "Off, No flash function"                              | 0x30 | 00110000 | No    |
    | "Fired, Red-eye reduction"                            | 0x41 | 01000001 | Yes   |
    | "Fired, Red-eye reduction, Return not detected"       | 0x45 | 01000101 | Yes   |
    | "Fired, Red-eye reduction, Return detected"           | 0x47 | 01000111 | Yes   |
    | "On, Red-eye reduction"                               | 0x49 | 01001001 | Yes   |
    | "On, Red-eye reduction, Return not detected"          | 0x4d | 01001101 | Yes   |
    | "On, Red-eye reduction, Return detected"              | 0x4f | 01001111 | Yes   |
    | "Off, Red-eye reduction"                              | 0x50 | 01010000 | No    |
    | "Auto, Did not fire, Red-eye reduction"               | 0x58 | 01011000 | No    |
    | "Auto, Fired, Red-eye reduction"                      | 0x59 | 01011001 | Yes   |
    | "Auto, Fired, Red-eye reduction, Return not detected" | 0x5d | 01011101 | Yes   |
    | "Auto, Fired, Red-eye reduction, Return detected"     | 0x5f | 01011111 | Yes   |
    +-------------------------------------------------------+------+----------+-------+

    :param exif_data:
    :return: If the flash was fired, or None if the exif information is not present
    """
    if 'Flash' not in exif_data:
        return None

    return bool((int(exif_data['Flash']) & 1) > 0)