// Generated by @novaclaw/httpapi-codegen. Do not edit.
import { Effect, Schema } from "effect"
import { Sse } from "effect/unstable/encoding"
import { HttpClientError } from "effect/unstable/http"
import { HttpApiClient, HttpApiEndpoint, HttpApiGroup } from "effect/unstable/httpapi"
import { ClientError } from "./client-error"

const Endpoint0Success = Schema.String

const Endpoint1Query = Schema.Struct({ archived: Schema.optionalKey(Schema.Union([Schema.Boolean, Schema.Undefined])) })

const Endpoint1Success = Schema.Array(Schema.String)

const Endpoint2Params = Schema.Struct({ sessionID: Schema.String })

const Endpoint2Success = Schema.Struct({ data: Schema.String })

class Endpoint2Error0Class extends Schema.TaggedErrorClass<Endpoint2Error0Class>("Missing")("Missing", {
  message: Schema.String,
}) {}
const Endpoint2Error0 = Endpoint2Error0Class.annotate({ httpApiStatus: 404 })

const Endpoint3Params = Schema.Struct({ sessionID: Schema.String })

const Endpoint3Success = Schema.Void.annotate({ httpApiStatus: 204 })

export const Group0 = HttpApiGroup.make("session", { topLevel: false })
  .add(HttpApiEndpoint.make("GET")("health", "/session/health", { success: Endpoint0Success }))
  .add(HttpApiEndpoint.make("GET")("list", "/session", { query: Endpoint1Query, success: Endpoint1Success }))
  .add(
    HttpApiEndpoint.make("GET")("get", "/session/:sessionID", {
      params: Endpoint2Params,
      success: Endpoint2Success,
      error: Endpoint2Error0,
    }),
  )
  .add(
    HttpApiEndpoint.make("POST")("interrupt", "/session/:sessionID/interrupt", {
      params: Endpoint3Params,
      success: Endpoint3Success,
    }),
  )

type RawGroup = HttpApiClient.Client.Group<typeof Group0, "session", never, never>

const Endpoint0DeclaredError = Schema.Never
const mapEndpoint0Error = (error: unknown) =>
  HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
    ? new ClientError({ cause: error })
    : Schema.is(Endpoint0DeclaredError)(error)
      ? error
      : new ClientError({ cause: error })
const Endpoint0 = (raw: RawGroup) => () => raw["health"]({}).pipe(Effect.mapError(mapEndpoint0Error))

type Endpoint1Input = { readonly archived?: (typeof Endpoint1Query.Type)["archived"] }
const Endpoint1DeclaredError = Schema.Never
const mapEndpoint1Error = (error: unknown) =>
  HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
    ? new ClientError({ cause: error })
    : Schema.is(Endpoint1DeclaredError)(error)
      ? error
      : new ClientError({ cause: error })
const Endpoint1 = (raw: RawGroup) => (input?: Endpoint1Input) =>
  raw["list"]({ query: { archived: input?.["archived"] } }).pipe(Effect.mapError(mapEndpoint1Error))

type Endpoint2Input = { readonly sessionID: (typeof Endpoint2Params.Type)["sessionID"] }
const Endpoint2DeclaredError = Schema.Union([Endpoint2Error0])
const mapEndpoint2Error = (error: unknown) =>
  HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
    ? new ClientError({ cause: error })
    : Schema.is(Endpoint2DeclaredError)(error)
      ? error
      : new ClientError({ cause: error })
const Endpoint2 = (raw: RawGroup) => (input: Endpoint2Input) =>
  raw["get"]({ params: { sessionID: input["sessionID"] } }).pipe(
    Effect.mapError(mapEndpoint2Error),
    Effect.map((value) => value.data),
  )

type Endpoint3Input = { readonly sessionID: (typeof Endpoint3Params.Type)["sessionID"] }
const Endpoint3DeclaredError = Schema.Never
const mapEndpoint3Error = (error: unknown) =>
  HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
    ? new ClientError({ cause: error })
    : Schema.is(Endpoint3DeclaredError)(error)
      ? error
      : new ClientError({ cause: error })
const Endpoint3 = (raw: RawGroup) => (input: Endpoint3Input) =>
  raw["interrupt"]({ params: { sessionID: input["sessionID"] } }).pipe(Effect.mapError(mapEndpoint3Error))

export const adaptGroup0 = (raw: RawGroup) => ({
  health: Endpoint0(raw),
  list: Endpoint1(raw),
  get: Endpoint2(raw),
  interrupt: Endpoint3(raw),
})
