/*
 * 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 {
  CustomFieldDateProperties,
  CustomFieldDateProperties$Outbound,
  CustomFieldDateProperties$outboundSchema,
} from "./customfielddateproperties.js";

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

/**
 * Schema to create a custom field of type date.
 */
export type CustomFieldCreateDate = {
  /**
   * 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: "date";
  /**
   * 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: CustomFieldDateProperties;
};

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

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

export function customFieldCreateDateMetadataToJSON(
  customFieldCreateDateMetadata: CustomFieldCreateDateMetadata,
): string {
  return JSON.stringify(
    CustomFieldCreateDateMetadata$outboundSchema.parse(
      customFieldCreateDateMetadata,
    ),
  );
}

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

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

export function customFieldCreateDateToJSON(
  customFieldCreateDate: CustomFieldCreateDate,
): string {
  return JSON.stringify(
    CustomFieldCreateDate$outboundSchema.parse(customFieldCreateDate),
  );
}
