import {
  jobSteps
} from "./chunk-OKXZ63IA.js";
import {
  DRIZZLE
} from "./chunk-U64T4YZE.js";
import {
  __decorateClass,
  __decorateParam
} from "./chunk-2E224ZSN.js";

// runtime/subsystems/jobs/job-step-service.drizzle-backend.ts
import { Inject, Injectable } from "@nestjs/common";
import { and, eq } from "drizzle-orm";
var DrizzleJobStepService = class {
  constructor(db) {
    this.db = db;
  }
  db;
  async recordStep(input) {
    const values = {
      jobRunId: input.jobRunId,
      stepId: input.stepId,
      kind: input.kind,
      seq: input.seq,
      status: input.status,
      input: input.input ?? null,
      output: input.output ?? null,
      error: input.error ?? null,
      attempts: input.attempts ?? 0,
      startedAt: input.startedAt ?? null,
      finishedAt: input.finishedAt ?? null
    };
    const [row] = await this.db.insert(jobSteps).values(values).onConflictDoUpdate({
      target: [jobSteps.jobRunId, jobSteps.stepId],
      set: {
        status: values.status,
        output: values.output,
        error: values.error,
        finishedAt: values.finishedAt,
        attempts: values.attempts
      }
    }).returning();
    return row;
  }
  async findStep(runId, stepId) {
    const [row] = await this.db.select().from(jobSteps).where(and(eq(jobSteps.jobRunId, runId), eq(jobSteps.stepId, stepId))).limit(1);
    return row ?? null;
  }
};
DrizzleJobStepService = __decorateClass([
  Injectable(),
  __decorateParam(0, Inject(DRIZZLE))
], DrizzleJobStepService);

export {
  DrizzleJobStepService
};
//# sourceMappingURL=chunk-DV4RV2DC.js.map