from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from src.domain.prompt_suggestions.models import PromptSuggestion


class PromptSuggestionRepository:
    def __init__(self, db: AsyncSession):
        self.db = db

    async def list(self, *, active_only: bool = False) -> list[PromptSuggestion]:
        query = select(PromptSuggestion)
        if active_only:
            query = query.where(PromptSuggestion.is_active.is_(True))
        result = await self.db.execute(query.order_by(PromptSuggestion.priority, PromptSuggestion.created_at))
        return list(result.scalars().all())

    async def get(self, suggestion_id):
        return await self.db.get(PromptSuggestion, suggestion_id)
