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

import * as z from "zod";
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";

/**
 * A party is a person, group, or organization that is involved in a contract and has legally binding obligations and responsibilities. They also seek to benefit from the agreement.
 *
 * @remarks
 */
export type Party = {
  /**
   * Unique identifier for the party, mapped to the party entity reference.
   */
  id: string;
  /**
   * Name of the party as it appears in the agreement.
   */
  nameInAgreement?: string | null | undefined;
  /**
   * Formal name of the party.
   */
  preferredName?: string | null | undefined;
};

/** @internal */
export const Party$inboundSchema: z.ZodType<Party, z.ZodTypeDef, unknown> = z
  .object({
    id: z.string(),
    name_in_agreement: z.nullable(z.string()).optional(),
    preferred_name: z.nullable(z.string()).optional(),
  }).transform((v) => {
    return remap$(v, {
      "name_in_agreement": "nameInAgreement",
      "preferred_name": "preferredName",
    });
  });

/** @internal */
export type Party$Outbound = {
  id: string;
  name_in_agreement?: string | null | undefined;
  preferred_name?: string | null | undefined;
};

/** @internal */
export const Party$outboundSchema: z.ZodType<
  Party$Outbound,
  z.ZodTypeDef,
  Party
> = z.object({
  id: z.string(),
  nameInAgreement: z.nullable(z.string()).optional(),
  preferredName: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    nameInAgreement: "name_in_agreement",
    preferredName: "preferred_name",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace Party$ {
  /** @deprecated use `Party$inboundSchema` instead. */
  export const inboundSchema = Party$inboundSchema;
  /** @deprecated use `Party$outboundSchema` instead. */
  export const outboundSchema = Party$outboundSchema;
  /** @deprecated use `Party$Outbound` instead. */
  export type Outbound = Party$Outbound;
}

export function partyToJSON(party: Party): string {
  return JSON.stringify(Party$outboundSchema.parse(party));
}

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