/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v4-mini";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type MeterQuantity = {
  /**
   * The timestamp for the current period.
   */
  timestamp: Date;
  /**
   * The quantity for the current period.
   */
  quantity: number;
};

/** @internal */
export const MeterQuantity$inboundSchema: z.ZodMiniType<
  MeterQuantity,
  unknown
> = z.object({
  timestamp: z.pipe(
    z.iso.datetime({ offset: true }),
    z.transform(v => new Date(v)),
  ),
  quantity: z.number(),
});

export function meterQuantityFromJSON(
  jsonString: string,
): SafeParseResult<MeterQuantity, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => MeterQuantity$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'MeterQuantity' from JSON`,
  );
}
