# -*- coding: utf-8 -*-
"""What the player's click or Back means for the server's game (no Kodi here: tests/test_remote_game.py).

The server's engine decides everything (rules, the exit prompt); the card only says which key was pressed.
"""
LETTERS = 'ABCD'
SAME = ('start', 'rules', 'back', 'next', 'again', 'results', 'retry', 'exit_stay', 'exit_confirm')
LIFELINES = {'life5050': 'fifty', 'lifetip': 'tip', 'lifeaudience': 'audience'}
LEAVE = ('title', 'home', 'end')           # another title / Home / leave: the ChatGPT game ends on every screen


def command(intent):
    """(action, answer) of a click on the card, or None (settings and the Příběh switch belong to the local game)."""
    if intent and intent.startswith('answer') and intent[6:].isdigit() and int(intent[6:]) < 4:
        return 'answer', LETTERS[int(intent[6:])]
    if intent in LIFELINES:
        return LIFELINES[intent], None
    if intent in SAME:
        return intent, None
    if intent in LEAVE:
        return 'close', None
    return None


def back(screen, exit_prompt):
    """Back on the remote: dismiss the exit prompt, leave from the title card, otherwise ask the engine (it confirms)."""
    if exit_prompt:
        return 'exit_stay', None
    if screen in (None, '', 'title'):
        return 'close', None
    return 'back', None
