import aiohttp


async def get(code: str) -> dict:
    """Look up a deck code."""
    async with aiohttp.ClientSession() as session:
        url = (
            "https://shadowverse-portal.com/api/v1/deck/import"
            f"?format=json&deck_code={code}"
        )
        async with session.get(url) as response:
            json = await response.json()
            if json["data"]["errors"]:
                return {"errors": json["data"]["errors"]}
            h = json["data"]["hash"]

        url = (
            "https://shadowverse-portal.com/api/v1/deck"
            f"?format=json&lang=en&hash={h}"
        )
        async with session.get(url) as response:
            json = await response.json()
            deck = json["data"]["deck"]

    return {"hash": h, "deck": deck}