from pydantic import BaseModel

from huesoporro.infra.repos import ChatbotRepo
from huesoporro.models import User


class IsModSvc(BaseModel):
    repo: ChatbotRepo

    async def run(self, username: str, channel: str, user: User) -> bool:
        """A user given username is a mod if they're the same as the current channel or if they're in the modlist
        available in a user's settings

        Args:
            username (str): The username to check if it's a mod
            channel (str): The current channel
            user (User): User object the chatbot belongs to
        """

        if channel == username:
            return True

        chatbot = await self.repo.get_by_user_id(user_id=user.id)
        if not chatbot:
            return False
        return username in chatbot.mods
