/*
 * 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 { smartUnion } from "../../types/smartUnion.js";
import {
  CustomFieldSelectProperties,
  CustomFieldSelectProperties$Outbound,
  CustomFieldSelectProperties$outboundSchema,
} from "./customfieldselectproperties.js";

export type CustomFieldCreateSelectMetadata =
  | string
  | number
  | number
  | boolean;

/**
 * Schema to create a custom field of type select.
 */
export type CustomFieldCreateSelect = {
  /**
   * Key-value object allowing you to store additional information.
   *
   * @remarks
   *
   * The key must be a string with a maximum length of **40 characters**.
   * The value must be either:
   *
   * * A string with a maximum length of **500 characters**
   * * An integer
   * * A floating-point number
   * * A boolean
   *
   * You can store up to **50 key-value pairs**.
   */
  metadata?: { [k: string]: string | number | number | boolean } | undefined;
  type: "select";
  /**
   * Identifier of the custom field. It'll be used as key when storing the value. Must be unique across the organization.It can only contain ASCII letters, numbers and hyphens.
   */
  slug: string;
  /**
   * Name of the custom field.
   */
  name: string;
  /**
   * The ID of the organization owning the custom field. **Required unless you use an organization token.**
   */
  organizationId?: string | null | undefined;
  properties: CustomFieldSelectProperties;
};

/** @internal */
export type CustomFieldCreateSelectMetadata$Outbound =
  | string
  | number
  | number
  | boolean;

/** @internal */
export const CustomFieldCreateSelectMetadata$outboundSchema: z.ZodMiniType<
  CustomFieldCreateSelectMetadata$Outbound,
  CustomFieldCreateSelectMetadata
> = smartUnion([z.string(), z.int(), z.number(), z.boolean()]);

export function customFieldCreateSelectMetadataToJSON(
  customFieldCreateSelectMetadata: CustomFieldCreateSelectMetadata,
): string {
  return JSON.stringify(
    CustomFieldCreateSelectMetadata$outboundSchema.parse(
      customFieldCreateSelectMetadata,
    ),
  );
}

/** @internal */
export type CustomFieldCreateSelect$Outbound = {
  metadata?: { [k: string]: string | number | number | boolean } | undefined;
  type: "select";
  slug: string;
  name: string;
  organization_id?: string | null | undefined;
  properties: CustomFieldSelectProperties$Outbound;
};

/** @internal */
export const CustomFieldCreateSelect$outboundSchema: z.ZodMiniType<
  CustomFieldCreateSelect$Outbound,
  CustomFieldCreateSelect
> = z.pipe(
  z.object({
    metadata: z.optional(
      z.record(
        z.string(),
        smartUnion([z.string(), z.int(), z.number(), z.boolean()]),
      ),
    ),
    type: z.literal("select"),
    slug: z.string(),
    name: z.string(),
    organizationId: z.optional(z.nullable(z.string())),
    properties: CustomFieldSelectProperties$outboundSchema,
  }),
  z.transform((v) => {
    return remap$(v, {
      organizationId: "organization_id",
    });
  }),
);

export function customFieldCreateSelectToJSON(
  customFieldCreateSelect: CustomFieldCreateSelect,
): string {
  return JSON.stringify(
    CustomFieldCreateSelect$outboundSchema.parse(customFieldCreateSelect),
  );
}
