# autocord
# package for simple automation with discord client
#
# m: user

import requests
from .Error import ApiError


class User():
    def __init__(self, token: str, http: requests.Session) -> None:
        self.token = token
        self.http = http

    def fetch(self, user: int):
        res = self.http.request(
            method="get",
            url=f"https://discord.com/api/v9/users/{user}",
        )

        if not res.ok:
            raise ApiError(res.json())

        return res.json()

    def profile(self, user: int, guild = 0):
        params = {}

        if guild:
            params["guild_id"] = guild

        res = self.http.request(
            method="get",
            url=f"https://discord.com/api/v9/users/{user}/profile",
            params=params
        )

        if not res.ok:
            raise ApiError(res.json())

        return res.json()
