/*
 * 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";

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

export type LicenseKeyValidate = {
  key: string;
  organizationId: string;
  activationId?: string | null | undefined;
  benefitId?: string | null | undefined;
  customerId?: string | null | undefined;
  incrementUsage?: number | null | undefined;
  /**
   * Key-value object allowing you to set conditions that must match when validating the license key.
   *
   * @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**.
   */
  conditions?: { [k: string]: string | number | number | boolean } | undefined;
};

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

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

export function conditionsToJSON(conditions: Conditions): string {
  return JSON.stringify(Conditions$outboundSchema.parse(conditions));
}

/** @internal */
export type LicenseKeyValidate$Outbound = {
  key: string;
  organization_id: string;
  activation_id?: string | null | undefined;
  benefit_id?: string | null | undefined;
  customer_id?: string | null | undefined;
  increment_usage?: number | null | undefined;
  conditions?: { [k: string]: string | number | number | boolean } | undefined;
};

/** @internal */
export const LicenseKeyValidate$outboundSchema: z.ZodMiniType<
  LicenseKeyValidate$Outbound,
  LicenseKeyValidate
> = z.pipe(
  z.object({
    key: z.string(),
    organizationId: z.string(),
    activationId: z.optional(z.nullable(z.string())),
    benefitId: z.optional(z.nullable(z.string())),
    customerId: z.optional(z.nullable(z.string())),
    incrementUsage: z.optional(z.nullable(z.int())),
    conditions: z.optional(
      z.record(
        z.string(),
        smartUnion([z.string(), z.int(), z.number(), z.boolean()]),
      ),
    ),
  }),
  z.transform((v) => {
    return remap$(v, {
      organizationId: "organization_id",
      activationId: "activation_id",
      benefitId: "benefit_id",
      customerId: "customer_id",
      incrementUsage: "increment_usage",
    });
  }),
);

export function licenseKeyValidateToJSON(
  licenseKeyValidate: LicenseKeyValidate,
): string {
  return JSON.stringify(
    LicenseKeyValidate$outboundSchema.parse(licenseKeyValidate),
  );
}
