/*
 * 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 {
  BenefitFeatureFlagCreateProperties,
  BenefitFeatureFlagCreateProperties$Outbound,
  BenefitFeatureFlagCreateProperties$outboundSchema,
} from "./benefitfeatureflagcreateproperties.js";
import {
  BenefitVisibility,
  BenefitVisibility$outboundSchema,
} from "./benefitvisibility.js";

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

/**
 * Schema to create a benefit of type `feature_flag`.
 */
export type BenefitFeatureFlagCreate = {
  /**
   * 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: "feature_flag";
  /**
   * The description of the benefit. Will be displayed on products having this benefit.
   */
  description: string;
  /**
   * The ID of the organization owning the benefit. **Required unless you use an organization token.**
   */
  organizationId?: string | null | undefined;
  /**
   * The visibility of the benefit in the customer portal.
   */
  visibility?: BenefitVisibility | null | undefined;
  /**
   * Properties for creating a benefit of type `feature_flag`.
   */
  properties: BenefitFeatureFlagCreateProperties;
};

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

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

export function benefitFeatureFlagCreateMetadataToJSON(
  benefitFeatureFlagCreateMetadata: BenefitFeatureFlagCreateMetadata,
): string {
  return JSON.stringify(
    BenefitFeatureFlagCreateMetadata$outboundSchema.parse(
      benefitFeatureFlagCreateMetadata,
    ),
  );
}

/** @internal */
export type BenefitFeatureFlagCreate$Outbound = {
  metadata?: { [k: string]: string | number | number | boolean } | undefined;
  type: "feature_flag";
  description: string;
  organization_id?: string | null | undefined;
  visibility?: string | null | undefined;
  properties: BenefitFeatureFlagCreateProperties$Outbound;
};

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

export function benefitFeatureFlagCreateToJSON(
  benefitFeatureFlagCreate: BenefitFeatureFlagCreate,
): string {
  return JSON.stringify(
    BenefitFeatureFlagCreate$outboundSchema.parse(benefitFeatureFlagCreate),
  );
}
