/*
 * 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 * as types from "../../types/primitives.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  ResourceMetadata,
  ResourceMetadata$inboundSchema,
} from "./resourcemetadata.js";

export type Self = {
  href?: string | undefined;
};

export type Collection = {
  href?: string | undefined;
};

export type ChangeAgreementTypeResponseAgreementTypes = {
  href?: string | undefined;
};

/**
 * Hypermedia links for the agreement.
 */
export type ChangeAgreementTypeResponseLinks = {
  self?: Self | undefined;
  collection?: Collection | undefined;
  agreementTypes?: ChangeAgreementTypeResponseAgreementTypes | undefined;
};

export type ChangeAgreementTypeResponseChangeType = {
  href?: string | undefined;
  method?: string | undefined;
  description?: string | undefined;
};

/**
 * Available actions on the agreement.
 */
export type Actions = {
  changeType?: ChangeAgreementTypeResponseChangeType | undefined;
};

/**
 * The updated agreement after a type change.
 */
export type ChangeAgreementTypeResponse = {
  /**
   * Unique identifier of the agreement.
   */
  id?: string | undefined;
  /**
   * Title of the agreement.
   */
  title?: string | undefined;
  /**
   * The updated agreement type.
   */
  type?: string | undefined;
  /**
   * Server-recomputed category based on new type.
   */
  category?: string | undefined;
  /**
   * Current status of the agreement.
   */
  status?: string | undefined;
  metadata?: ResourceMetadata | undefined;
  /**
   * Hypermedia links for the agreement.
   */
  links?: ChangeAgreementTypeResponseLinks | undefined;
  /**
   * Available actions on the agreement.
   */
  actions?: Actions | undefined;
};

/** @internal */
export const Self$inboundSchema: z.ZodType<Self, z.ZodTypeDef, unknown> = z
  .object({
    href: types.optional(types.string()),
  });

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

/** @internal */
export const Collection$inboundSchema: z.ZodType<
  Collection,
  z.ZodTypeDef,
  unknown
> = z.object({
  href: types.optional(types.string()),
});

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

/** @internal */
export const ChangeAgreementTypeResponseAgreementTypes$inboundSchema: z.ZodType<
  ChangeAgreementTypeResponseAgreementTypes,
  z.ZodTypeDef,
  unknown
> = z.object({
  href: types.optional(types.string()),
});

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

/** @internal */
export const ChangeAgreementTypeResponseLinks$inboundSchema: z.ZodType<
  ChangeAgreementTypeResponseLinks,
  z.ZodTypeDef,
  unknown
> = z.object({
  self: types.optional(z.lazy(() => Self$inboundSchema)),
  collection: types.optional(z.lazy(() => Collection$inboundSchema)),
  agreement_types: types.optional(
    z.lazy(() => ChangeAgreementTypeResponseAgreementTypes$inboundSchema),
  ),
}).transform((v) => {
  return remap$(v, {
    "agreement_types": "agreementTypes",
  });
});

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

/** @internal */
export const ChangeAgreementTypeResponseChangeType$inboundSchema: z.ZodType<
  ChangeAgreementTypeResponseChangeType,
  z.ZodTypeDef,
  unknown
> = z.object({
  href: types.optional(types.string()),
  method: types.optional(types.string()),
  description: types.optional(types.string()),
});

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

/** @internal */
export const Actions$inboundSchema: z.ZodType<Actions, z.ZodTypeDef, unknown> =
  z.object({
    change_type: types.optional(
      z.lazy(() => ChangeAgreementTypeResponseChangeType$inboundSchema),
    ),
  }).transform((v) => {
    return remap$(v, {
      "change_type": "changeType",
    });
  });

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

/** @internal */
export const ChangeAgreementTypeResponse$inboundSchema: z.ZodType<
  ChangeAgreementTypeResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.optional(types.string()),
  title: types.optional(types.string()),
  type: types.optional(types.string()),
  category: types.optional(types.string()),
  status: types.optional(types.string()),
  metadata: types.optional(ResourceMetadata$inboundSchema),
  _links: types.optional(
    z.lazy(() => ChangeAgreementTypeResponseLinks$inboundSchema),
  ),
  _actions: types.optional(z.lazy(() => Actions$inboundSchema)),
}).transform((v) => {
  return remap$(v, {
    "_links": "links",
    "_actions": "actions",
  });
});

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