/*
 * 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 TargetResourceRep = {
  links?: { [k: string]: Link } | undefined;
  /**
   * The name of the resource
   */
  name?: string | undefined;
  /**
   * The resource specifier
   */
  resources?: Array<string> | undefined;
};

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

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

export function targetResourceRepToJSON(
  targetResourceRep: TargetResourceRep,
): string {
  return JSON.stringify(
    TargetResourceRep$outboundSchema.parse(targetResourceRep),
  );
}
export function targetResourceRepFromJSON(
  jsonString: string,
): SafeParseResult<TargetResourceRep, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => TargetResourceRep$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'TargetResourceRep' from JSON`,
  );
}
