import datetime

from pydantic import BaseModel

from src.huesoporro.models import Quote, User
from src.huesoporro.svc.is_mod import IsModSvc
from src.huesoporro.svc.quote_storer_svc import QuoteStorerSvc


class StoreQuoteAction(BaseModel):
    quote_storer_svc: QuoteStorerSvc
    is_mod_svc: IsModSvc

    async def run(
        self, user: User, channel: str, quote: str, author: str, username: str
    ) -> Quote | None:
        if not await self.is_mod_svc.run(user=user, username=username, channel=channel):
            return None
        new_quote = Quote(
            quote=quote,
            author=User(user=author, external_auth={}),
            channel=User(user=channel, external_auth={}),
            created_at=datetime.datetime.now(datetime.UTC),
            last_updated_at=datetime.datetime.now(datetime.UTC),
        )
        return await self.quote_storer_svc.run(new_quote)
