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

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

export type CustomFieldTextProperties = {
  formLabel?: string | undefined;
  formHelpText?: string | undefined;
  formPlaceholder?: string | undefined;
  textarea?: boolean | undefined;
  minLength?: number | undefined;
  maxLength?: number | undefined;
};

/** @internal */
export const CustomFieldTextProperties$inboundSchema: z.ZodMiniType<
  CustomFieldTextProperties,
  unknown
> = z.pipe(
  z.object({
    form_label: z.optional(z.string()),
    form_help_text: z.optional(z.string()),
    form_placeholder: z.optional(z.string()),
    textarea: z.optional(z.boolean()),
    min_length: z.optional(z.int()),
    max_length: z.optional(z.int()),
  }),
  z.transform((v) => {
    return remap$(v, {
      "form_label": "formLabel",
      "form_help_text": "formHelpText",
      "form_placeholder": "formPlaceholder",
      "min_length": "minLength",
      "max_length": "maxLength",
    });
  }),
);
/** @internal */
export type CustomFieldTextProperties$Outbound = {
  form_label?: string | undefined;
  form_help_text?: string | undefined;
  form_placeholder?: string | undefined;
  textarea?: boolean | undefined;
  min_length?: number | undefined;
  max_length?: number | undefined;
};

/** @internal */
export const CustomFieldTextProperties$outboundSchema: z.ZodMiniType<
  CustomFieldTextProperties$Outbound,
  CustomFieldTextProperties
> = z.pipe(
  z.object({
    formLabel: z.optional(z.string()),
    formHelpText: z.optional(z.string()),
    formPlaceholder: z.optional(z.string()),
    textarea: z.optional(z.boolean()),
    minLength: z.optional(z.int()),
    maxLength: z.optional(z.int()),
  }),
  z.transform((v) => {
    return remap$(v, {
      formLabel: "form_label",
      formHelpText: "form_help_text",
      formPlaceholder: "form_placeholder",
      minLength: "min_length",
      maxLength: "max_length",
    });
  }),
);

export function customFieldTextPropertiesToJSON(
  customFieldTextProperties: CustomFieldTextProperties,
): string {
  return JSON.stringify(
    CustomFieldTextProperties$outboundSchema.parse(customFieldTextProperties),
  );
}
export function customFieldTextPropertiesFromJSON(
  jsonString: string,
): SafeParseResult<CustomFieldTextProperties, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => CustomFieldTextProperties$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'CustomFieldTextProperties' from JSON`,
  );
}
