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

import sqlalchemy
import sqlalchemy.ext.asyncio

from . import models


TRANSITION_TASK_STATE = """-- name: transition_task_state \\:one
SELECT transition_task_state(
    :p1\\:\\:UUID,
    :p2\\:\\:task_run_status
) AS task_run
"""


@dataclasses.dataclass()
class TransitionTaskStateParams:
    task_id: uuid.UUID
    next_state: Any


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

    def transition_task_state(self, arg: TransitionTaskStateParams) -> Optional[Optional[Any]]:
        row = self._conn.execute(sqlalchemy.text(TRANSITION_TASK_STATE), {"p1": arg.task_id, "p2": arg.next_state}).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 transition_task_state(self, arg: TransitionTaskStateParams) -> Optional[Optional[Any]]:
        row = (await self._conn.execute(sqlalchemy.text(TRANSITION_TASK_STATE), {"p1": arg.task_id, "p2": arg.next_state})).first()
        if row is None:
            return None
        return row[0]
