1import * as Effect from "effect/Effect";
2import type { CatalogsServingConfig } from "./CatalogsServingConfig.ts";
3import { bindGcpHost } from "../Host.ts";
4import { grantFor, type BindingIam, type GcpHttpOp } from "../HttpBinding.ts";
5
6/**
7 * Shared HTTP scaffolding for Retail serving-config bindings.
8 * NOT exported from index.ts.
9 */
10export const makeServingConfigHttpBinding = <
11 I extends { placement: string },
12 A,
13 E,
14>(options: {
15 tag: string;
16 iam: BindingIam;
17 operation: GcpHttpOp<I, A, E>;
18}) =>
19 Effect.gen(function* () {
20 const run = yield* options.operation;
21 return Effect.fn(function* (servingConfig: CatalogsServingConfig) {
22 yield* bindGcpHost({
23 tag: options.tag,
24 resource: servingConfig,
25 iam: [grantFor(options.iam, servingConfig.name)],
26 });
27 const name = yield* servingConfig.name;
28 return Effect.fn(`${options.tag}(${servingConfig.LogicalId})`)(function* (
29 request: Omit<I, "placement">,
30 ) {
31 return yield* run({
32 ...request,
33 placement: yield* name,
34 } as I);
35 });
36 });
37 });