/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: 8ac6d82b05c8
 */

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import * as openEnums from "../../types/enums.js";
import { OpenEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  VespaSearchIndexInfoResponse,
  VespaSearchIndexInfoResponse$inboundSchema,
} from "./vespasearchindexinforesponse.js";

export const SearchIndexResponseStatus = {
  Online: "online",
  Offline: "offline",
} as const;
export type SearchIndexResponseStatus = OpenEnum<
  typeof SearchIndexResponseStatus
>;

export type SearchIndexResponseIndex = VespaSearchIndexInfoResponse;

export type SearchIndexResponse = {
  id: string;
  name: string;
  creatorId: string;
  documentCount: number;
  status: SearchIndexResponseStatus;
  createdAt: Date;
  modifiedAt: Date;
  index: VespaSearchIndexInfoResponse;
};

/** @internal */
export const SearchIndexResponseStatus$inboundSchema: z.ZodType<
  SearchIndexResponseStatus,
  unknown
> = openEnums.inboundSchema(SearchIndexResponseStatus);

/** @internal */
export const SearchIndexResponseIndex$inboundSchema: z.ZodType<
  SearchIndexResponseIndex,
  unknown
> = VespaSearchIndexInfoResponse$inboundSchema;

export function searchIndexResponseIndexFromJSON(
  jsonString: string,
): SafeParseResult<SearchIndexResponseIndex, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => SearchIndexResponseIndex$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'SearchIndexResponseIndex' from JSON`,
  );
}

/** @internal */
export const SearchIndexResponse$inboundSchema: z.ZodType<
  SearchIndexResponse,
  unknown
> = z.object({
  id: z.string(),
  name: z.string(),
  creator_id: z.string(),
  document_count: z.int(),
  status: SearchIndexResponseStatus$inboundSchema,
  created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  modified_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  index: VespaSearchIndexInfoResponse$inboundSchema,
}).transform((v) => {
  return remap$(v, {
    "creator_id": "creatorId",
    "document_count": "documentCount",
    "created_at": "createdAt",
    "modified_at": "modifiedAt",
  });
});

export function searchIndexResponseFromJSON(
  jsonString: string,
): SafeParseResult<SearchIndexResponse, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => SearchIndexResponse$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'SearchIndexResponse' from JSON`,
  );
}
