# Code generated by sqlc. DO NOT EDIT.
# versions:
#   sqlc v1.29.0
# source: get_hype_cron_job_by_name.sql
import dataclasses
from typing import Optional

import sqlalchemy
import sqlalchemy.ext.asyncio

from . import models


GET_HYPE_CRON_JOB_BY_NAME = """-- name: get_hype_cron_job_by_name \\:one
SELECT jobid, schedule, command_type, command_params, active, jobname, activated_at, scheduled_jobs_confirmed_until, should_backfill FROM hype_cron_job
WHERE jobname = :p1
"""


@dataclasses.dataclass()
class GetHypeCronJobByNameParams:
    jobname: str


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

    def get_hype_cron_job_by_name(self, arg: GetHypeCronJobByNameParams) -> Optional[models.HypeCronJob]:
        row = self._conn.execute(sqlalchemy.text(GET_HYPE_CRON_JOB_BY_NAME), {"p1": arg.jobname}).first()
        if row is None:
            return None
        return models.HypeCronJob(
            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_hype_cron_job_by_name(self, arg: GetHypeCronJobByNameParams) -> Optional[models.HypeCronJob]:
        row = (await self._conn.execute(sqlalchemy.text(GET_HYPE_CRON_JOB_BY_NAME), {"p1": arg.jobname})).first()
        if row is None:
            return None
        return models.HypeCronJob(
            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],
        )
