<reponame>Albatrous/genshin.py
import pytest

from genshin import GenshinClient


@pytest.mark.asyncio
async def test_calculator_characters(client: GenshinClient):
    characters = await client.get_calculator_characters()
    characters.sort(key=lambda c: c.id)

    assert len(characters) >= 43

    character = characters[0]
    assert character.name == "<NAME>"
    assert "genshin" in character.icon
    assert character.max_level == 90
    assert character.level == 0
    assert not character.collab


@pytest.mark.asyncio
async def test_calculator_weapons(client: GenshinClient):
    weapons = await client.get_calculator_weapons()
    weapons.sort(key=lambda w: w.id)

    assert len(weapons) >= 126

    weapon = weapons[0]
    assert weapon.name == "Dull Blade"
    assert weapon.max_level == 70
    assert weapon.level == 0


@pytest.mark.asyncio
async def test_calculator_artifacts(client: GenshinClient):
    artifacts = await client.get_calculator_artifacts()
    artifacts.sort(key=lambda a: a.id)

    assert len(artifacts) >= 69

    artifact = artifacts[0]
    assert artifact.name == "Heart of Comradeship"
    assert artifact.max_level == 12
    assert artifact.level == 0


@pytest.mark.asyncio
async def test_character_talents(client: GenshinClient):
    talents = await client.get_character_talents(10000002)
    talents.sort(key=lambda t: t.group_id)

    # special character - has dash
    # fmt: off
    assert len(talents) == 7
    assert talents[0].type == "passive" and talents[0].name == "<NAME>"
    assert talents[1].type == "passive" and talents[1].name == "<NAME>"
    assert talents[2].type == "passive" and talents[2].name == "<NAME>"
    assert talents[3].type == "attack"  and talents[3].name == "Normal Attack: Kamisato Art - Kabuki"
    assert talents[4].type == "skill"   and talents[4].name == "Kamisato Art: Hyouka"
    assert talents[5].type == "dash"    and talents[5].name == "Kamisato Art: Senho"
    assert talents[6].type == "burst"   and talents[6].name == "Kamisato Art: Soumetsu"
    # fmt: on

    assert talents[0].max_level == 1
    assert talents[6].max_level == 10


@pytest.mark.asyncio
async def test_complete_artifact_set(client: GenshinClient):
    artifact_id = 7554  # Gladiator's Nostalgia (feather / pos #1)

    artifacts = await client.get_complete_artifact_set(artifact_id)
    artifacts.sort(key=lambda x: x.pos)

    assert len(artifacts) == 4
    assert artifact_id not in (a.id for a in artifacts)

    assert artifacts[0].id == 7552 and artifacts[0].name == "Gladiator's Destiny"
    assert artifacts[1].id == 7555 and artifacts[1].name == "Gladiator's Longing"
    assert artifacts[2].id == 7551 and artifacts[2].name == "Gladiator's Intoxication"
    assert artifacts[3].id == 7553 and artifacts[3].name == "Gladiator's Triumphus"


@pytest.mark.asyncio
async def test_calculate(client: GenshinClient):
    cost = await (
        client.calculator()
        .set_character(10000052, current=1, target=90)
        .set_weapon(11509, current=1, target=90)
        .add_artifact(9651, current=0, target=20, full_set=True)
        .with_current_talents(current=1, target=10)
    )

    assert len(cost.character) == 11
    assert len(cost.weapon) == 12
    assert len(cost.artifacts) == 5 and all(len(i.list) == 2 for i in cost.artifacts)
    assert len(cost.talents) == 9
    assert len(cost.total) == 25
    assert cost.total[0].name == "Mora" and cost.total[0].amount == 9_533_850


@pytest.mark.asyncio
async def test_calculator_characters_synced(lclient: GenshinClient):
    characters = await lclient.get_calculator_characters(sync=True)
    assert characters[0].level != 0


@pytest.mark.asyncio
async def test_character_details(lclient: GenshinClient):
    # <NAME>
    details = await lclient.get_character_details(10000046)
    assert details.weapon.level >= 80
