import datetime
import uuid

from pydantic import BaseModel

from huesoporro.models import Quote, User
from huesoporro.svc.is_mod import IsModSvc
from huesoporro.svc.quotes_svcs import CreateQuoteSvc


class CreateQuoteAction(BaseModel):
    create_quote_svc: CreateQuoteSvc
    is_mod_svc: IsModSvc

    async def run(  # noqa: PLR0913
        self,
        user: User,
        channel: str,
        quote: str,
        author: str,
        username: str,
        is_active: bool = True,
    ) -> Quote | None:
        if not await self.is_mod_svc.run(user=user, username=username, channel=channel):
            return None
        new_quote = Quote(
            id=uuid.uuid4(),
            quote=quote,
            author=author,
            channel_name=channel,
            created_at=datetime.datetime.now(datetime.UTC),
            is_active=is_active,
            last_updated_at=datetime.datetime.now(datetime.UTC),
        )
        return await self.create_quote_svc.run(new_quote)
