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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  ConversationPayload,
  ConversationPayload$inboundSchema,
} from "./conversationpayload.js";
import {
  ConversationSource,
  ConversationSource$inboundSchema,
} from "./conversationsource.js";

export type DatasetRecord = {
  id: string;
  createdAt: Date;
  updatedAt: Date;
  deletedAt: Date | null;
  datasetId: string;
  payload: ConversationPayload;
  properties: { [k: string]: any };
  source: ConversationSource;
};

/** @internal */
export const DatasetRecord$inboundSchema: z.ZodType<DatasetRecord, unknown> = z
  .object({
    id: z.string(),
    created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
    updated_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
    deleted_at: z.nullable(
      z.iso.datetime({ offset: true }).transform(v => new Date(v)),
    ),
    dataset_id: z.string(),
    payload: ConversationPayload$inboundSchema,
    properties: z.record(z.string(), z.any()),
    source: ConversationSource$inboundSchema,
  }).transform((v) => {
    return remap$(v, {
      "created_at": "createdAt",
      "updated_at": "updatedAt",
      "deleted_at": "deletedAt",
      "dataset_id": "datasetId",
    });
  });

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