/*
 * 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 { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  MeterUnit,
  MeterUnit$inboundSchema,
  MeterUnit$outboundSchema,
} from "./meterunit.js";

/**
 * A meter associated to a metered price.
 */
export type ProductPriceMeter = {
  /**
   * The ID of the object.
   */
  id: string;
  /**
   * The name of the meter.
   */
  name: string;
  unit: MeterUnit;
  /**
   * The label for the custom unit.
   */
  customLabel: string | null;
  /**
   * The multiplier to convert from base unit to display scale.
   */
  customMultiplier: number | null;
};

/** @internal */
export const ProductPriceMeter$inboundSchema: z.ZodMiniType<
  ProductPriceMeter,
  unknown
> = z.pipe(
  z.object({
    id: z.string(),
    name: z.string(),
    unit: MeterUnit$inboundSchema,
    custom_label: z.nullable(z.string()),
    custom_multiplier: z.nullable(z.int()),
  }),
  z.transform((v) => {
    return remap$(v, {
      "custom_label": "customLabel",
      "custom_multiplier": "customMultiplier",
    });
  }),
);
/** @internal */
export type ProductPriceMeter$Outbound = {
  id: string;
  name: string;
  unit: string;
  custom_label: string | null;
  custom_multiplier: number | null;
};

/** @internal */
export const ProductPriceMeter$outboundSchema: z.ZodMiniType<
  ProductPriceMeter$Outbound,
  ProductPriceMeter
> = z.pipe(
  z.object({
    id: z.string(),
    name: z.string(),
    unit: MeterUnit$outboundSchema,
    customLabel: z.nullable(z.string()),
    customMultiplier: z.nullable(z.int()),
  }),
  z.transform((v) => {
    return remap$(v, {
      customLabel: "custom_label",
      customMultiplier: "custom_multiplier",
    });
  }),
);

export function productPriceMeterToJSON(
  productPriceMeter: ProductPriceMeter,
): string {
  return JSON.stringify(
    ProductPriceMeter$outboundSchema.parse(productPriceMeter),
  );
}
export function productPriceMeterFromJSON(
  jsonString: string,
): SafeParseResult<ProductPriceMeter, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ProductPriceMeter$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ProductPriceMeter' from JSON`,
  );
}
