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

export type CustomerCustomerMeterMeter = {
  /**
   * Creation timestamp of the object.
   */
  createdAt: Date;
  /**
   * Last modification timestamp of the object.
   */
  modifiedAt: Date | null;
  /**
   * The ID of the object.
   */
  id: string;
  /**
   * The name of the meter. Will be shown on customer's invoices and usage.
   */
  name: string;
};

/** @internal */
export const CustomerCustomerMeterMeter$inboundSchema: z.ZodMiniType<
  CustomerCustomerMeterMeter,
  unknown
> = z.pipe(
  z.object({
    created_at: z.pipe(
      z.iso.datetime({ offset: true }),
      z.transform(v => new Date(v)),
    ),
    modified_at: z.nullable(
      z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))),
    ),
    id: z.string(),
    name: z.string(),
  }),
  z.transform((v) => {
    return remap$(v, {
      "created_at": "createdAt",
      "modified_at": "modifiedAt",
    });
  }),
);

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