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

import * as z from "zod/v3";
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 {
  Link,
  Link$inboundSchema,
  Link$Outbound,
  Link$outboundSchema,
} from "./link.js";

export type SubjectDataRep = {
  links?: { [k: string]: Link } | undefined;
  /**
   * The subject's name
   */
  name?: string | undefined;
  /**
   * The subject's avatar
   */
  avatarUrl?: string | undefined;
};

/** @internal */
export const SubjectDataRep$inboundSchema: z.ZodType<
  SubjectDataRep,
  z.ZodTypeDef,
  unknown
> = z.object({
  _links: z.record(Link$inboundSchema).optional(),
  name: z.string().optional(),
  avatarUrl: z.string().optional(),
}).transform((v) => {
  return remap$(v, {
    "_links": "links",
  });
});
/** @internal */
export type SubjectDataRep$Outbound = {
  _links?: { [k: string]: Link$Outbound } | undefined;
  name?: string | undefined;
  avatarUrl?: string | undefined;
};

/** @internal */
export const SubjectDataRep$outboundSchema: z.ZodType<
  SubjectDataRep$Outbound,
  z.ZodTypeDef,
  SubjectDataRep
> = z.object({
  links: z.record(Link$outboundSchema).optional(),
  name: z.string().optional(),
  avatarUrl: z.string().optional(),
}).transform((v) => {
  return remap$(v, {
    links: "_links",
  });
});

export function subjectDataRepToJSON(subjectDataRep: SubjectDataRep): string {
  return JSON.stringify(SubjectDataRep$outboundSchema.parse(subjectDataRep));
}
export function subjectDataRepFromJSON(
  jsonString: string,
): SafeParseResult<SubjectDataRep, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => SubjectDataRep$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'SubjectDataRep' from JSON`,
  );
}
