# -*- coding: utf-8 -*-
"""Dev-only listing of the fixture titles as playable canonical URLs (live scenario 6, docs/plan/milionar-library 120 §3).

Only answers while the fixture provider is enabled. L3 replaces it with the real My movies / My series listings.
"""
import xbmcgui
import xbmcplugin

from wcs.library2 import fixture_provider, store, urls

ITEMS = (('movie', 900101, None, None, 'Fixture Film 1'), ('movie', 900102, None, None, 'Fixture Film 2'),
         ('episode', 900001, 1, 1, 'Fixture Show S01E01'), ('episode', 900001, 1, 2, 'Fixture Show S01E02'))


def run(handle, params):
    if fixture_provider.enabled():
        entries = []
        for kind, tmdb_id, season, episode, label in ITEMS:
            canonical = urls.movie_url(tmdb_id) if kind == 'movie' else urls.episode_url(tmdb_id, season, episode)
            state = store.get_state('movie' if kind == 'movie' else 'tv', tmdb_id, season, episode) or {}
            item = xbmcgui.ListItem(label=label, path=canonical)
            item.setProperty('IsPlayable', 'true')
            tag = item.getVideoInfoTag()
            tag.setTitle(label)
            tag.setMediaType('movie' if kind == 'movie' else 'episode')
            tag.setPlaycount(int(state.get('playcount') or 0))
            if state.get('resume_pos'):
                tag.setResumePoint(float(state['resume_pos']), float(state.get('resume_total') or 0))
            entries.append((canonical, item, False))
        xbmcplugin.addDirectoryItems(handle, entries, len(entries))
    xbmcplugin.endOfDirectory(handle, cacheToDisc=False)
