from __future__ import annotations

from dataclasses import dataclass

from .pattern_controller import PatternController
from .show_controller import ShowController
from .shifted_season_controller import ShiftedSeasonController
from .tag_controller import TagController
from .tmdb_controller import TmdbController
from .track_controller import TrackController


@dataclass(frozen=True)
class ScreenBootstrap:
    context: dict
    configuration_data: dict
    signature_tags: dict
    remove_global_keys: list
    ignore_global_keys: list
    remove_track_keys: list
    ignore_track_keys: list


def build_screen_bootstrap(context: dict) -> ScreenBootstrap:
    configurationData = context['config'].getData()
    metadataConfiguration = configurationData.get('metadata', {})
    streamMetadataConfiguration = metadataConfiguration.get('streams', {})

    return ScreenBootstrap(
        context=context,
        configuration_data=configurationData,
        signature_tags=metadataConfiguration.get('signature', {}),
        remove_global_keys=metadataConfiguration.get('remove', []),
        ignore_global_keys=metadataConfiguration.get('ignore', []),
        remove_track_keys=streamMetadataConfiguration.get('remove', []),
        ignore_track_keys=streamMetadataConfiguration.get('ignore', []),
    )


def build_screen_controllers(
    context: dict,
    *,
    pattern: bool = False,
    show: bool = False,
    track: bool = False,
    tag: bool = False,
    tmdb: bool = False,
    shifted_season: bool = False,
) -> dict[str, object]:
    controllers = {}

    if pattern:
        controllers['pattern'] = PatternController(context=context)
    if show:
        controllers['show'] = ShowController(context=context)
    if track:
        controllers['track'] = TrackController(context=context)
    if tag:
        controllers['tag'] = TagController(context=context)
    if tmdb:
        controllers['tmdb'] = TmdbController()
    if shifted_season:
        controllers['shifted_season'] = ShiftedSeasonController(context=context)

    return controllers
