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

import sqlalchemy
import sqlalchemy.ext.asyncio

from . import models


UPDATE_WORKFLOW_RUN_STATUS = """-- name: update_workflow_run_status \\:exec
UPDATE hyrex_workflow_run
SET status = :p1\\:\\:workflow_run_status,
    last_heartbeat = now(),
    finished = CASE 
        WHEN :p1\\:\\:workflow_run_status IN ('SUCCESS', 'FAILED', 'CANCELED') THEN now()
        ELSE finished
    END
WHERE id = :p2
"""


@dataclasses.dataclass()
class UpdateWorkflowRunStatusParams:
    status: Any
    id: uuid.UUID


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

    def update_workflow_run_status(self, arg: UpdateWorkflowRunStatusParams) -> None:
        self._conn.execute(sqlalchemy.text(UPDATE_WORKFLOW_RUN_STATUS), {"p1": arg.status, "p2": arg.id})


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

    async def update_workflow_run_status(self, arg: UpdateWorkflowRunStatusParams) -> None:
        await self._conn.execute(sqlalchemy.text(UPDATE_WORKFLOW_RUN_STATUS), {"p1": arg.status, "p2": arg.id})
