class PartialCommunity:
    """Represents a Weverse Community with partial information available.

    Inherited by:

    - :class:`Community`

    .. container:: operations

        .. describe:: x == y

            Checks if two communities are equal.

        .. describe:: x != y

            Checks if two communities are not equal.

        .. describe:: hash(x)

            Returns the community's hash.

        .. describe:: str(x)

            Returns the community's name.

    Attributes
    ----------
    data: :class:`dict`
        The raw data directly taken from the response generated by Weverse's API.
    id: :class:`int`
        The ID of the community.
    name: :class:`str`
        The official name of the community.
    logo_image_url: :class:`str`
        The URL to the logo image of the community.
    """

    __slots__ = ("data", "id", "name", "logo_image_url")

    def __init__(self, data: dict):
        self.data: dict = data
        self.id: int = data["communityId"]
        self.name: str = data["communityName"]
        self.logo_image_url: str = data["logoImage"]

    def __eq__(self, other):
        if isinstance(other, self.__class__):
            return self.id == other.id

        raise NotImplementedError

    def __repr__(self):
        return f"Partial Community community_id={self.id}, name={self.name}"

    def __str__(self):
        return self.name

    def __hash__(self):
        return hash(self.id)

    @property
    def url(self) -> str:
        """:class:`str`: Returns the URL of the Weverse Community's Artist tab."""
        return f"https://weverse.io/{self.data['urlPath']}/artist"


class Community(PartialCommunity):
    """Represents a Weverse Community. Inherits from :class:`PartialCommunity`.

    Shares the same attributes and operations with :class:`PartialCommunity`.

    Attributes
    ----------
    alias: :class:`str`
        The alias of the community.
    agency_profile_name: :class:`str`
        The profile name of the community's agency profile.
    agency_image_url: :class:`str`
        The URL of the profile image of the community's agency profile.
    agency_cover_image_url: :class:`str`
        The URL of the cover image of the community's agency profile.
    home_header_image_url: :class:`str`
        The URL of the home header of the community.
    home_gradation_colour: :class:`dict`
        The dictionary that contains the colour combinations displayed
        on the community's home page.
    has_membership: :class:`bool`
        Whether the community has paid membership benefits.
    member_count: :class:`int`
        The number of members who joined the community.
    fandom_name: :class:`str` | :class:`None`
        The fandom name of the community, if any.
    fan_event_url: :class:`str` | :class:`None`
        The URL used to participate in the fan events of the community, if any.
    artist_code: :class:`str` | :class:`None`
        The artist code of the community, if any.
    open_date: :class:`str` | :class:`None`
        The date the community got created on Weverse, if any.
    """

    __slots__ = (
        "alias",
        "agency_profile_name",
        "agency_image_url",
        "agency_cover_image_url",
        "home_header_image_url",
        "home_gradation_colour",
        "has_membership",
        "member_count",
        "fandom_name",
        "fan_event_url",
        "artist_code",
        "open_date",
    )

    def __init__(self, data: dict):
        super().__init__(data)
        self.alias: str = data["communityAlias"]
        self.agency_profile_name: str = data["agencyProfile"]["profileName"]
        self.agency_image_url: str = data["agencyProfile"]["profileImageUrl"]
        self.agency_cover_image_url: str = data["agencyProfile"]["profileCoverImageUrl"]
        self.home_header_image_url: str = data["homeHeaderImage"]
        self.home_gradation_colour: dict = data["homeGradationColor"]
        self.has_membership: bool = data["hasMembershipProduct"]
        self.member_count: int = data["memberCount"]
        self.fandom_name: str | None = data.get("fandomName")
        self.fan_event_url: str | None = data.get("fanEventUrl")
        self.artist_code: str | None = data.get("artistCode")
        self.open_date: str | None = data.get("openDate")

    def __repr__(self):
        return f"Community community_id={self.id}, name={self.name}"
