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

import sqlalchemy
import sqlalchemy.ext.asyncio

from . import models


CONDITIONALLY_RETRY_TASK = """-- name: conditionally_retry_task \\:one
SELECT result FROM conditionally_retry_task(
    :p1\\:\\:UUID,
    :p2\\:\\:UUID,
    :p3\\:\\:INT
) AS result
"""


@dataclasses.dataclass()
class ConditionallyRetryTaskParams:
    existing_task_id: uuid.UUID
    new_task_id: uuid.UUID
    timeout_seconds: Optional[int]


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

    def conditionally_retry_task(self, arg: ConditionallyRetryTaskParams) -> Optional[Optional[Any]]:
        row = self._conn.execute(sqlalchemy.text(CONDITIONALLY_RETRY_TASK), {"p1": arg.existing_task_id, "p2": arg.new_task_id, "p3": arg.timeout_seconds}).first()
        if row is None:
            return None
        return row[0]


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

    async def conditionally_retry_task(self, arg: ConditionallyRetryTaskParams) -> Optional[Optional[Any]]:
        row = (await self._conn.execute(sqlalchemy.text(CONDITIONALLY_RETRY_TASK), {"p1": arg.existing_task_id, "p2": arg.new_task_id, "p3": arg.timeout_seconds})).first()
        if row is None:
            return None
        return row[0]
