import type {} from "@atcute/lexicons";
import * as v from "@atcute/lexicons/validations";
import type {} from "@atcute/lexicons/ambient";

const _linkDescriptorSchema = /*#__PURE__*/ v.object({
  $type: /*#__PURE__*/ v.optional(
    /*#__PURE__*/ v.literal("sh.tangled.query.enrichResponse#linkDescriptor"),
  ),
  /**
   * Collection whose records are linked, a colon, then an index-backed path (subject or .repo).
   */
  source: /*#__PURE__*/ v.string(),
  /**
   * Record paths into the inner response selecting references for this payload. All references are considered when omitted.
   */
  targets: /*#__PURE__*/ v.optional(
    /*#__PURE__*/ v.array(/*#__PURE__*/ v.string()),
  ),
  /**
   * NSID of the payload type to produce, which also defines the payload's shape. Results land at data[ref][source][type].
   */
  type: /*#__PURE__*/ v.string<
    | "com.bad-example.identity.miniDoc"
    | "sh.tangled.query.enrichResponse#count"
    | "sh.tangled.query.enrichResponse#distinctAuthors"
    | "sh.tangled.query.enrichResponse#viewer"
    | (string & {})
  >(),
});
const _mainSchema = /*#__PURE__*/ v.procedure(
  "sh.tangled.query.enrichResponse",
  {
    params: null,
    input: {
      type: "lex",
      schema: /*#__PURE__*/ v.object({
        /**
         * Payloads to compute for each found reference.
         */
        get enrich() {
          return /*#__PURE__*/ v.array(linkDescriptorSchema);
        },
        /**
         * Parameters for the inner query, exactly as it declares them.
         */
        params: /*#__PURE__*/ v.optional(/*#__PURE__*/ v.unknown()),
        /**
         * DID whose own relation to each reference is looked up for viewer payloads. Required when any descriptor requests one.
         */
        viewer: /*#__PURE__*/ v.optional(/*#__PURE__*/ v.didString()),
        /**
         * NSID of the inner query to run, e.g. sh.tangled.repo.listRepos.
         */
        xrpc: /*#__PURE__*/ v.nsidString(),
      }),
    },
    output: {
      type: "lex",
      schema: /*#__PURE__*/ v.object({
        /**
         * Reference (did or at-uri) -> link source -> payload type nsid -> payload. References no descriptor applies to are absent.
         */
        data: /*#__PURE__*/ v.unknown(),
        /**
         * The inner query's response, unmodified.
         */
        output: /*#__PURE__*/ v.unknown(),
      }),
    },
  },
);

type linkDescriptor$schematype = typeof _linkDescriptorSchema;
type main$schematype = typeof _mainSchema;

export interface linkDescriptorSchema extends linkDescriptor$schematype {}
export interface mainSchema extends main$schematype {}

export const linkDescriptorSchema =
  _linkDescriptorSchema as linkDescriptorSchema;
export const mainSchema = _mainSchema as mainSchema;

export interface LinkDescriptor extends v.InferInput<
  typeof linkDescriptorSchema
> {}

export interface $params {}
export interface $input extends v.InferXRPCBodyInput<mainSchema["input"]> {}
export interface $output extends v.InferXRPCBodyInput<mainSchema["output"]> {}

declare module "@atcute/lexicons/ambient" {
  interface XRPCProcedures {
    "sh.tangled.query.enrichResponse": mainSchema;
  }
}
