# -*- coding: utf-8 -*-
"""Milionář — the only way into the game: one subject, one window (the modern card).

    open_game(subject, content=None)   open the game window here (blocks until it is closed)
    run(params)                        the plugin action `milionar_game` (router)
    start(subject)                     open it through the plugin (RunPlugin), e.g. from the service or a closing dialog

`subject` is a `wcs.games.millionaire.subject.Subject`; `content` a content source (wcs/games/content), None = the
live AI chat.
"""
import xbmc

from wcs.games.millionaire.subject import Subject, from_params, from_person, plugin_url, query  # noqa: F401


def open_game(subject, content=None, demo_id='', mode=None):
    from wcs.games.DialogMilionarGame import MilionarGameModal
    from wcs.games.designs import MODERN
    modal = MilionarGameModal(title=subject.title, fanart=subject.poster, plot=subject.plot, genre=subject.genre,
                              media_type=subject.media_type, actor_data=subject.person,
                              banner_fanart=subject.backdrop or None, episode_title=subject.episode_title,
                              season_number=subject.season_number, episode_number=subject.episode_number,
                              content=content, year=subject.year, subject=subject, design=MODERN,
                              demo_id=demo_id, mode=mode)
    modal.doModal()
    del modal


def run(params):
    open_game(from_params(params), mode=params.get('mode'))


def start(subject):
    xbmc.executebuiltin('RunPlugin({})'.format(plugin_url(subject)))
