from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession

from src.db.models.rf_project_report_line import RfProjectReportLine



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

    async def get(self, line_id: int) -> RfProjectReportLine | None:
        query = select(
            RfProjectReportLine
        ).where(
            RfProjectReportLine.id == line_id
        ).limit(1)
        return (await self.db.execute(query)).scalar_one_or_none()

    async def get_list(self, line_ids: list[int]) -> list[RfProjectReportLine]:
        query = select(
            RfProjectReportLine
        ).where(
            RfProjectReportLine.id.in_(line_ids)
        )
        return (await self.db.execute(query)).scalars().all()

    async def get_ids(
            self,
            project_report_id: int,
    ) -> list[int]:
        
        query = select(
            RfProjectReportLine.id
        ).where(
            RfProjectReportLine.rf_project_report_id == project_report_id
        )
        return (await self.db.execute(query)).scalars().all()
        
