/*
 * 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 { smartUnion } from "../../types/smartUnion.js";
import {
  CustomerMeterSortProperty,
  CustomerMeterSortProperty$outboundSchema,
} from "../components/customermetersortproperty.js";
import {
  ListResourceCustomerMeter,
  ListResourceCustomerMeter$inboundSchema,
} from "../components/listresourcecustomermeter.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

/**
 * Filter by organization ID.
 */
export type CustomerMetersListQueryParamOrganizationIDFilter =
  | string
  | Array<string>;

/**
 * Filter by customer ID.
 */
export type CustomerMetersListQueryParamCustomerIDFilter =
  | string
  | Array<string>;

/**
 * Filter by external customer ID.
 */
export type CustomerMetersListQueryParamExternalCustomerIDFilter =
  | string
  | Array<string>;

/**
 * Filter by meter ID.
 */
export type QueryParamMeterIDFilter = string | Array<string>;

export type CustomerMetersListRequest = {
  /**
   * Filter by organization ID.
   */
  organizationId?: string | Array<string> | null | undefined;
  /**
   * Filter by customer ID.
   */
  customerId?: string | Array<string> | null | undefined;
  /**
   * Filter by external customer ID.
   */
  externalCustomerId?: string | Array<string> | null | undefined;
  /**
   * Filter by meter ID.
   */
  meterId?: string | Array<string> | null | undefined;
  /**
   * Page number, defaults to 1.
   */
  page?: number | undefined;
  /**
   * Size of a page, defaults to 10. Maximum is 100.
   */
  limit?: number | undefined;
  /**
   * Sorting criterion. Several criteria can be used simultaneously and will be applied in order. Add a minus sign `-` before the criteria name to sort by descending order.
   */
  sorting?: Array<CustomerMeterSortProperty> | null | undefined;
};

export type CustomerMetersListResponse = {
  result: ListResourceCustomerMeter;
};

/** @internal */
export type CustomerMetersListQueryParamOrganizationIDFilter$Outbound =
  | string
  | Array<string>;

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

export function customerMetersListQueryParamOrganizationIDFilterToJSON(
  customerMetersListQueryParamOrganizationIDFilter:
    CustomerMetersListQueryParamOrganizationIDFilter,
): string {
  return JSON.stringify(
    CustomerMetersListQueryParamOrganizationIDFilter$outboundSchema.parse(
      customerMetersListQueryParamOrganizationIDFilter,
    ),
  );
}

/** @internal */
export type CustomerMetersListQueryParamCustomerIDFilter$Outbound =
  | string
  | Array<string>;

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

export function customerMetersListQueryParamCustomerIDFilterToJSON(
  customerMetersListQueryParamCustomerIDFilter:
    CustomerMetersListQueryParamCustomerIDFilter,
): string {
  return JSON.stringify(
    CustomerMetersListQueryParamCustomerIDFilter$outboundSchema.parse(
      customerMetersListQueryParamCustomerIDFilter,
    ),
  );
}

/** @internal */
export type CustomerMetersListQueryParamExternalCustomerIDFilter$Outbound =
  | string
  | Array<string>;

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

export function customerMetersListQueryParamExternalCustomerIDFilterToJSON(
  customerMetersListQueryParamExternalCustomerIDFilter:
    CustomerMetersListQueryParamExternalCustomerIDFilter,
): string {
  return JSON.stringify(
    CustomerMetersListQueryParamExternalCustomerIDFilter$outboundSchema.parse(
      customerMetersListQueryParamExternalCustomerIDFilter,
    ),
  );
}

/** @internal */
export type QueryParamMeterIDFilter$Outbound = string | Array<string>;

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

export function queryParamMeterIDFilterToJSON(
  queryParamMeterIDFilter: QueryParamMeterIDFilter,
): string {
  return JSON.stringify(
    QueryParamMeterIDFilter$outboundSchema.parse(queryParamMeterIDFilter),
  );
}

/** @internal */
export type CustomerMetersListRequest$Outbound = {
  organization_id?: string | Array<string> | null | undefined;
  customer_id?: string | Array<string> | null | undefined;
  external_customer_id?: string | Array<string> | null | undefined;
  meter_id?: string | Array<string> | null | undefined;
  page: number;
  limit: number;
  sorting?: Array<string> | null | undefined;
};

/** @internal */
export const CustomerMetersListRequest$outboundSchema: z.ZodMiniType<
  CustomerMetersListRequest$Outbound,
  CustomerMetersListRequest
> = z.pipe(
  z.object({
    organizationId: z.optional(
      z.nullable(smartUnion([z.string(), z.array(z.string())])),
    ),
    customerId: z.optional(
      z.nullable(smartUnion([z.string(), z.array(z.string())])),
    ),
    externalCustomerId: z.optional(
      z.nullable(smartUnion([z.string(), z.array(z.string())])),
    ),
    meterId: z.optional(
      z.nullable(smartUnion([z.string(), z.array(z.string())])),
    ),
    page: z._default(z.int(), 1),
    limit: z._default(z.int(), 10),
    sorting: z.optional(
      z.nullable(z.array(CustomerMeterSortProperty$outboundSchema)),
    ),
  }),
  z.transform((v) => {
    return remap$(v, {
      organizationId: "organization_id",
      customerId: "customer_id",
      externalCustomerId: "external_customer_id",
      meterId: "meter_id",
    });
  }),
);

export function customerMetersListRequestToJSON(
  customerMetersListRequest: CustomerMetersListRequest,
): string {
  return JSON.stringify(
    CustomerMetersListRequest$outboundSchema.parse(customerMetersListRequest),
  );
}

/** @internal */
export const CustomerMetersListResponse$inboundSchema: z.ZodMiniType<
  CustomerMetersListResponse,
  unknown
> = z.pipe(
  z.object({
    Result: ListResourceCustomerMeter$inboundSchema,
  }),
  z.transform((v) => {
    return remap$(v, {
      "Result": "result",
    });
  }),
);

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