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

export type LicenseKeyUpdate = {
  status?: LicenseKeyStatus | null | undefined;
  usage?: number | undefined;
  limitActivations?: number | null | undefined;
  limitUsage?: number | null | undefined;
  expiresAt?: Date | null | undefined;
};

/** @internal */
export type LicenseKeyUpdate$Outbound = {
  status?: string | null | undefined;
  usage: number;
  limit_activations?: number | null | undefined;
  limit_usage?: number | null | undefined;
  expires_at?: string | null | undefined;
};

/** @internal */
export const LicenseKeyUpdate$outboundSchema: z.ZodMiniType<
  LicenseKeyUpdate$Outbound,
  LicenseKeyUpdate
> = z.pipe(
  z.object({
    status: z.optional(z.nullable(LicenseKeyStatus$outboundSchema)),
    usage: z._default(z.int(), 0),
    limitActivations: z.optional(z.nullable(z.int())),
    limitUsage: z.optional(z.nullable(z.int())),
    expiresAt: z.optional(
      z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))),
    ),
  }),
  z.transform((v) => {
    return remap$(v, {
      limitActivations: "limit_activations",
      limitUsage: "limit_usage",
      expiresAt: "expires_at",
    });
  }),
);

export function licenseKeyUpdateToJSON(
  licenseKeyUpdate: LicenseKeyUpdate,
): string {
  return JSON.stringify(
    LicenseKeyUpdate$outboundSchema.parse(licenseKeyUpdate),
  );
}
