import { Hono } from "hono"
import { describeRoute, validator, resolver } from "hono-openapi"
import { SessionID, MessageID, PartID } from "@/session/schema"
import z from "zod"
import { Session } from "@/session/session"
import { MessageV2 } from "@/session/message-v2"
import { SessionPrompt } from "@/session/prompt"
import { SessionRunState } from "@/session/run-state"
import { SessionCompaction } from "@/session/compaction"
import { SessionRevert } from "@/session/revert"
import { SessionShare } from "@/share/session"
import { SessionStatus } from "@/session/status"
import { SessionSummary } from "@/session/summary"
import { Todo } from "@/session/todo"
import { Agent } from "@/agent/agent"
import { Snapshot } from "@/snapshot"
import { Command } from "@/command"
import * as Log from "@saeeol/core/util/log"
import { Permission } from "@/permission"
import { PermissionID } from "@/permission/schema"
import { ModelID, ProviderID } from "@/provider/schema"
import { errors } from "../../../error"
import { zodObject } from "@/util/effect-zod"
import { Bus } from "@/bus"
import { NamedError } from "@saeeol/core/util/error"
import { jsonRequest, runRequest } from "../trace"

export const log = Log.create({ service: "server" })

export const QueryBoolean = z.union([
  z.preprocess((value) => (value === "true" ? true : value === "false" ? false : value), z.boolean()),
  z.enum(["true", "false"]),
])

export function queryBoolean(value: z.infer<typeof QueryBoolean> | undefined) {
  if (value === undefined) return
  return value === true || value === "true"
}

export {
  Hono,
  describeRoute,
  validator,
  resolver,
  z,
  Session,
  MessageV2,
  SessionPrompt,
  SessionRunState,
  SessionCompaction,
  SessionRevert,
  SessionShare,
  SessionStatus,
  SessionSummary,
  Todo,
  Agent,
  Snapshot,
  Command,
  Permission,
  PermissionID,
  ModelID,
  ProviderID,
  errors,
  zodObject,
  Bus,
  NamedError,
  jsonRequest,
  runRequest,
  SessionID,
  MessageID,
  PartID,
}
