import "./chunk-P2WKYAC5.js";
import "./chunk-B4YGTZF6.js";
import "./chunk-MLNVNVRI.js";
import {
  ConfiguredCredentialBinding,
  ConnectionId,
  ScopeId,
  SecretId,
  credentialSlotPart
} from "./chunk-ZANQD7E2.js";
import "./chunk-7D4SUZUM.js";

// src/http-source.ts
import { Effect, Schema } from "effect";
var HttpCredentialInput = Schema.Union([
  Schema.String,
  Schema.Struct({
    kind: Schema.Literal("text"),
    text: Schema.String,
    prefix: Schema.optional(Schema.String)
  }),
  Schema.Struct({
    kind: Schema.Literal("secret"),
    secretId: Schema.String,
    secretScope: Schema.optional(Schema.String),
    prefix: Schema.optional(Schema.String)
  }),
  Schema.Struct({
    kind: Schema.Literal("connection"),
    connectionId: Schema.String
  })
]);
var HttpConfiguredValueInput = Schema.Union([
  Schema.String,
  Schema.Struct({
    kind: Schema.Literal("secret"),
    prefix: Schema.optional(Schema.String)
  })
]);
var OAuth2Flow = Schema.Literals(["authorizationCode", "clientCredentials"]);
var OAuth2SourceConfig = Schema.Struct({
  kind: Schema.Literal("oauth2"),
  securitySchemeName: Schema.String,
  flow: OAuth2Flow,
  tokenUrl: Schema.String,
  authorizationUrl: Schema.NullOr(Schema.String).pipe(
    Schema.optional,
    Schema.withDecodingDefault(Effect.succeed(null))
  ),
  issuerUrl: Schema.optional(Schema.NullOr(Schema.String)),
  clientIdSlot: Schema.String,
  clientSecretSlot: Schema.NullOr(Schema.String),
  connectionSlot: Schema.String,
  scopes: Schema.Array(Schema.String)
}).annotate({ identifier: "OAuth2SourceConfig" });
var HttpOAuthConfigureInput = Schema.Struct({
  clientId: Schema.optional(HttpCredentialInput),
  clientSecret: Schema.optional(Schema.NullOr(HttpCredentialInput)),
  connection: Schema.optional(HttpCredentialInput)
}).annotate({ identifier: "HttpOAuthConfigureInput" });
var httpCredentialSlotKey = (section, placement, name) => `${section}.${placement}.${credentialSlotPart(name)}`;
var httpHeaderSlotKey = (section, name) => httpCredentialSlotKey(section, "headers", name);
var httpQuerySlotKey = (section, name) => httpCredentialSlotKey(section, "query", name);
var httpOAuthConnectionSlotKey = (section) => `${section}.oauth.connection`;
var httpOAuthClientIdSlotKey = (section) => `${section}.oauth.clientId`;
var httpOAuthClientSecretSlotKey = (section) => `${section}.oauth.clientSecret`;
var httpSectionSlotPrefix = (section) => `${section}.`;
var compileHttpNamedCredentialMap = (values, slotForName) => {
  const nextValues = {};
  const bindings = [];
  for (const [name, value] of Object.entries(values ?? {})) {
    if (typeof value === "string") {
      nextValues[name] = value;
      continue;
    }
    if ("kind" in value) {
      if (value.kind === "binding") {
        nextValues[name] = value;
        continue;
      }
      const slot2 = slotForName(name);
      nextValues[name] = ConfiguredCredentialBinding.make({
        kind: "binding",
        slot: slot2,
        prefix: "prefix" in value ? value.prefix : void 0
      });
      bindings.push({
        slot: slot2,
        value: httpCredentialInputToBindingValue(value)
      });
      continue;
    }
    const slot = slotForName(name);
    nextValues[name] = ConfiguredCredentialBinding.make({
      kind: "binding",
      slot,
      prefix: value.prefix
    });
    bindings.push({
      slot,
      targetScope: "targetScope" in value ? value.targetScope : void 0,
      value: {
        kind: "secret",
        secretId: SecretId.make(value.secretId),
        ..."secretScopeId" in value && value.secretScopeId ? { secretScopeId: ScopeId.make(value.secretScopeId) } : {}
      }
    });
  }
  return { values: nextValues, bindings };
};
var httpCredentialInputToBindingValue = (input) => {
  if (typeof input === "string") {
    return {
      kind: "text",
      text: input
    };
  }
  if (input.kind === "text") {
    return {
      kind: "text",
      text: input.text
    };
  }
  if (input.kind === "secret") {
    return {
      kind: "secret",
      secretId: SecretId.make(input.secretId),
      ...input.secretScope ? { secretScopeId: ScopeId.make(input.secretScope) } : {}
    };
  }
  if (input.kind === "connection") {
    return {
      kind: "connection",
      connectionId: ConnectionId.make(input.connectionId)
    };
  }
  return input;
};
export {
  HttpConfiguredValueInput,
  HttpCredentialInput,
  HttpOAuthConfigureInput,
  OAuth2Flow,
  OAuth2SourceConfig,
  compileHttpNamedCredentialMap,
  httpCredentialInputToBindingValue,
  httpCredentialSlotKey,
  httpHeaderSlotKey,
  httpOAuthClientIdSlotKey,
  httpOAuthClientSecretSlotKey,
  httpOAuthConnectionSlotKey,
  httpQuerySlotKey,
  httpSectionSlotPrefix
};
//# sourceMappingURL=http-source.js.map