from pydantic import BaseModel

from src.huesoporro.infra.db import Database
from src.huesoporro.models import User


class IsModSvc(BaseModel):
    db: Database

    async def run(self, user: User, username: str, channel: str) -> 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"""

        if channel == username:
            return True

        chatbot_settings = await self.db.get_chatbot_settings(user=user)
        if not chatbot_settings:
            return False
        return username in chatbot_settings.mods
