# Code generated by sqlc. DO NOT EDIT.
# versions:
#   sqlc v1.29.0
# source: get_active_hype_cron_jobs.sql
import dataclasses
import datetime
from typing import Any, AsyncIterator, Iterator, Optional

import sqlalchemy
import sqlalchemy.ext.asyncio

from . import models


GET_ACTIVE_HYPE_CRON_JOBS = """-- name: get_active_hype_cron_jobs \\:many
  SELECT jobid, schedule, command_type\\:\\:text, command_params, active, jobname, activated_at,
  scheduled_jobs_confirmed_until, should_backfill
  FROM hype_cron_job
  WHERE active = true
  ORDER BY jobid
"""


@dataclasses.dataclass()
class GetActiveHypeCronJobsParams:

    pass

@dataclasses.dataclass()
class GetActiveHypeCronJobsRow:
    jobid: int
    schedule: Optional[str]
    command_type: str
    command_params: Any
    active: bool
    jobname: str
    activated_at: Optional[datetime.datetime]
    scheduled_jobs_confirmed_until: Optional[datetime.datetime]
    should_backfill: Optional[bool]


class Querier:
    def __init__(self, conn: sqlalchemy.engine.Connection):
        self._conn = conn

    def get_active_hype_cron_jobs(self, arg: GetActiveHypeCronJobsParams) -> Iterator[GetActiveHypeCronJobsRow]:
        result = self._conn.execute(sqlalchemy.text(GET_ACTIVE_HYPE_CRON_JOBS))
        for row in result:
            yield GetActiveHypeCronJobsRow(
                jobid=row[0],
                schedule=row[1],
                command_type=row[2],
                command_params=row[3],
                active=row[4],
                jobname=row[5],
                activated_at=row[6],
                scheduled_jobs_confirmed_until=row[7],
                should_backfill=row[8],
            )


class AsyncQuerier:
    def __init__(self, conn: sqlalchemy.ext.asyncio.AsyncConnection):
        self._conn = conn

    async def get_active_hype_cron_jobs(self, arg: GetActiveHypeCronJobsParams) -> AsyncIterator[GetActiveHypeCronJobsRow]:
        result = await self._conn.stream(sqlalchemy.text(GET_ACTIVE_HYPE_CRON_JOBS))
        async for row in result:
            yield GetActiveHypeCronJobsRow(
                jobid=row[0],
                schedule=row[1],
                command_type=row[2],
                command_params=row[3],
                active=row[4],
                jobname=row[5],
                activated_at=row[6],
                scheduled_jobs_confirmed_until=row[7],
                should_backfill=row[8],
            )
