import { WS_METHODS } from "@t3tools/contracts";
import { Atom } from "effect/reactivity";
import { createEnvironmentRpcCommand, createEnvironmentRpcQueryAtomFamily } from "./runtime.ts";
import type { EnvironmentRegistry } from "../connection/registry.ts";
import * as Persistence from "../platform/persistence.ts";
import { vcsCommandConcurrency, vcsCommandScheduler } from "./vcsCommandScheduler.ts";
import { invalidateCachedVcsRefs } from "./vcsRefInvalidation.ts";
export function createGitEnvironmentAtoms<R, E>(
runtime: Atom.AtomRuntime<EnvironmentRegistry | Persistence.EnvironmentCacheStore | R, E>,
) {
return {
pullRequestResolution: createEnvironmentRpcQueryAtomFamily(runtime, {
label: "environment-data:git:resolve-pull-request",
tag: WS_METHODS.gitResolvePullRequest,
}),
preparePullRequestThread: createEnvironmentRpcCommand(runtime, {
label: "environment-data:git:prepare-pull-request-thread",
tag: WS_METHODS.gitPreparePullRequestThread,
scheduler: vcsCommandScheduler,
concurrency: vcsCommandConcurrency,
onSettled: ({ environmentId, input }, registry) =>
invalidateCachedVcsRefs(registry, { environmentId, cwd: input.cwd }),
}),
};
}