from typing import TypedDict

from folkugat_web.model import playlists as model

PlaylistRowTuple = tuple[int, str | None, int]
PlaylistEntryRowTuple = tuple[int, int, int, int | None, int | None]


class PlaylistRowDict(TypedDict):
    id: int | None
    playlist_id: int
    set_id: int
    tema_id: int | None
    score_id: int | None


def playlist_entry_to_row(tema_in_set: model.PlaylistEntry) -> PlaylistRowDict:
    return {
        'id': tema_in_set.id,
        'playlist_id': tema_in_set.playlist_id,
        'set_id': tema_in_set.set_id,
        'tema_id': tema_in_set.tema_id,
        'score_id': tema_in_set.score_id,
    }


def row_to_playlist_entry(row: PlaylistEntryRowTuple) -> model.PlaylistEntry:
    return model.PlaylistEntry(
        id=row[0],
        playlist_id=row[1],
        set_id=row[2],
        tema_id=row[3],
        score_id=row[4],
    )


def row_to_playlist(row: PlaylistRowTuple) -> model.Playlist:
    return model.Playlist(
        id=row[0],
        name=row[1],
        sets=[],  # Empty for list view
        hidden=bool(row[2]),
    )
