/*
 * 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 { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import {
  Note,
  Note$inboundSchema,
  Note$Outbound,
  Note$outboundSchema,
} from "../components/note.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

/**
 * The format of the note content to be created. The `plaintext` format uses the line feed character `\n` to create new lines within the note content. The `markdown` format supports rich text formatting, and links.
 */
export const PostV2NotesFormat = {
  Plaintext: "plaintext",
  Markdown: "markdown",
} as const;
/**
 * The format of the note content to be created. The `plaintext` format uses the line feed character `\n` to create new lines within the note content. The `markdown` format supports rich text formatting, and links.
 */
export type PostV2NotesFormat = ClosedEnum<typeof PostV2NotesFormat>;

export type PostV2NotesData = {
  /**
   * The ID or slug of the parent object the note belongs to.
   */
  parentObject: string;
  /**
   * The ID of the parent record the note belongs to.
   */
  parentRecordId: string;
  /**
   * The note title. The title is plaintext only and has no formatting.
   */
  title: string;
  /**
   * The format of the note content to be created. The `plaintext` format uses the line feed character `\n` to create new lines within the note content. The `markdown` format supports rich text formatting, and links.
   */
  format: PostV2NotesFormat;
  /**
   * The representation of the note content in the specified format.
   */
  content: string;
  /**
   * `created_at` will default to the current time. However, if you wish to backdate a note for migration or other purposes, you can override with a custom `created_at` value. Note that dates before 1970 or in the future are not allowed.
   */
  createdAt?: string | undefined;
};

export type PostV2NotesRequest = {
  data: PostV2NotesData;
};

/**
 * Success
 */
export type PostV2NotesResponse = {
  data: Note;
};

/** @internal */
export const PostV2NotesFormat$inboundSchema: z.ZodNativeEnum<
  typeof PostV2NotesFormat
> = z.nativeEnum(PostV2NotesFormat);

/** @internal */
export const PostV2NotesFormat$outboundSchema: z.ZodNativeEnum<
  typeof PostV2NotesFormat
> = PostV2NotesFormat$inboundSchema;

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

/** @internal */
export const PostV2NotesData$inboundSchema: z.ZodType<
  PostV2NotesData,
  z.ZodTypeDef,
  unknown
> = z.object({
  parent_object: z.string(),
  parent_record_id: z.string(),
  title: z.string(),
  format: PostV2NotesFormat$inboundSchema,
  content: z.string(),
  created_at: z.string().optional(),
}).transform((v) => {
  return remap$(v, {
    "parent_object": "parentObject",
    "parent_record_id": "parentRecordId",
    "created_at": "createdAt",
  });
});

/** @internal */
export type PostV2NotesData$Outbound = {
  parent_object: string;
  parent_record_id: string;
  title: string;
  format: string;
  content: string;
  created_at?: string | undefined;
};

/** @internal */
export const PostV2NotesData$outboundSchema: z.ZodType<
  PostV2NotesData$Outbound,
  z.ZodTypeDef,
  PostV2NotesData
> = z.object({
  parentObject: z.string(),
  parentRecordId: z.string(),
  title: z.string(),
  format: PostV2NotesFormat$outboundSchema,
  content: z.string(),
  createdAt: z.string().optional(),
}).transform((v) => {
  return remap$(v, {
    parentObject: "parent_object",
    parentRecordId: "parent_record_id",
    createdAt: "created_at",
  });
});

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

export function postV2NotesDataToJSON(
  postV2NotesData: PostV2NotesData,
): string {
  return JSON.stringify(PostV2NotesData$outboundSchema.parse(postV2NotesData));
}

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

/** @internal */
export const PostV2NotesRequest$inboundSchema: z.ZodType<
  PostV2NotesRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  data: z.lazy(() => PostV2NotesData$inboundSchema),
});

/** @internal */
export type PostV2NotesRequest$Outbound = {
  data: PostV2NotesData$Outbound;
};

/** @internal */
export const PostV2NotesRequest$outboundSchema: z.ZodType<
  PostV2NotesRequest$Outbound,
  z.ZodTypeDef,
  PostV2NotesRequest
> = z.object({
  data: z.lazy(() => PostV2NotesData$outboundSchema),
});

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

export function postV2NotesRequestToJSON(
  postV2NotesRequest: PostV2NotesRequest,
): string {
  return JSON.stringify(
    PostV2NotesRequest$outboundSchema.parse(postV2NotesRequest),
  );
}

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

/** @internal */
export const PostV2NotesResponse$inboundSchema: z.ZodType<
  PostV2NotesResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  data: Note$inboundSchema,
});

/** @internal */
export type PostV2NotesResponse$Outbound = {
  data: Note$Outbound;
};

/** @internal */
export const PostV2NotesResponse$outboundSchema: z.ZodType<
  PostV2NotesResponse$Outbound,
  z.ZodTypeDef,
  PostV2NotesResponse
> = z.object({
  data: Note$outboundSchema,
});

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

export function postV2NotesResponseToJSON(
  postV2NotesResponse: PostV2NotesResponse,
): string {
  return JSON.stringify(
    PostV2NotesResponse$outboundSchema.parse(postV2NotesResponse),
  );
}

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