import pytest
from moviebox_api.core import Search, SubjectType
from moviebox_api.models import SearchResults
from tests import init_search


# TODO: [fix] These first 2 tests fails due to async loop timing out
@pytest.mark.asyncio
@pytest.mark.parametrize(
    argnames=["subject_type"],
    argvalues=(
        [SubjectType.ALL],
        [SubjectType.MOVIES],
        [SubjectType.TV_SERIES],
        [SubjectType.MUSIC],
    ),
)
async def test_get_content(subject_type: SubjectType):
    search: Search = init_search(subject_type=subject_type)
    contents = await search.get_content()
    assert type(contents) is dict


@pytest.mark.asyncio
@pytest.mark.parametrize(
    argnames=["subject_type"],
    argvalues=(
        [SubjectType.ALL],
        [SubjectType.MOVIES],
        [SubjectType.TV_SERIES],
        [SubjectType.MUSIC],
    ),
)
async def test_model_content(subject_type: SubjectType):
    search: Search = init_search(subject_type=subject_type)
    modelled_contents = await search.get_modelled_content()
    assert isinstance(modelled_contents, SearchResults)
    for item in modelled_contents.items:
        assert item.subjectType == subject_type


@pytest.mark.asyncio
async def test_next_page_navigation():
    search = init_search()
    contents = await search.get_modelled_content()
    assert isinstance(contents, SearchResults)
    next_search = search.next_page(contents)
    assert isinstance(next_search, Search)
    next_contents = await next_search.get_modelled_content()
    assert isinstance(next_contents, SearchResults)
    assert contents.pager.page + 1 == next_contents.pager.page


@pytest.mark.asyncio
async def test_previous_page_navigation():
    search: Search = init_search(page=3)
    contents = await search.get_modelled_content()
    assert isinstance(contents, SearchResults)
    previous_search = search.previous_page(contents)
    assert isinstance(previous_search, Search)
    previous_contents = await previous_search.get_modelled_content()
    assert isinstance(previous_contents, SearchResults)
    assert contents.pager.page - 1 == previous_contents.pager.page
