/*
 * 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 {
  CustomerSubscriptionSortProperty,
  CustomerSubscriptionSortProperty$outboundSchema,
} from "../components/customersubscriptionsortproperty.js";
import {
  ListResourceCustomerSubscription,
  ListResourceCustomerSubscription$inboundSchema,
} from "../components/listresourcecustomersubscription.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type CustomerPortalSubscriptionsListSecurity = {
  customerSession?: string | undefined;
  memberSession?: string | undefined;
};

/**
 * Filter by product ID.
 */
export type CustomerPortalSubscriptionsListQueryParamProductIDFilter =
  | string
  | Array<string>;

export type CustomerPortalSubscriptionsListRequest = {
  /**
   * Filter by product ID.
   */
  productId?: string | Array<string> | null | undefined;
  /**
   * Filter by active or cancelled subscription.
   */
  active?: boolean | null | undefined;
  /**
   * Search by product or organization name.
   */
  query?: 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<CustomerSubscriptionSortProperty> | null | undefined;
};

export type CustomerPortalSubscriptionsListResponse = {
  result: ListResourceCustomerSubscription;
};

/** @internal */
export type CustomerPortalSubscriptionsListSecurity$Outbound = {
  customer_session?: string | undefined;
  member_session?: string | undefined;
};

/** @internal */
export const CustomerPortalSubscriptionsListSecurity$outboundSchema:
  z.ZodMiniType<
    CustomerPortalSubscriptionsListSecurity$Outbound,
    CustomerPortalSubscriptionsListSecurity
  > = z.pipe(
    z.object({
      customerSession: z.optional(z.string()),
      memberSession: z.optional(z.string()),
    }),
    z.transform((v) => {
      return remap$(v, {
        customerSession: "customer_session",
        memberSession: "member_session",
      });
    }),
  );

export function customerPortalSubscriptionsListSecurityToJSON(
  customerPortalSubscriptionsListSecurity:
    CustomerPortalSubscriptionsListSecurity,
): string {
  return JSON.stringify(
    CustomerPortalSubscriptionsListSecurity$outboundSchema.parse(
      customerPortalSubscriptionsListSecurity,
    ),
  );
}

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

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

export function customerPortalSubscriptionsListQueryParamProductIDFilterToJSON(
  customerPortalSubscriptionsListQueryParamProductIDFilter:
    CustomerPortalSubscriptionsListQueryParamProductIDFilter,
): string {
  return JSON.stringify(
    CustomerPortalSubscriptionsListQueryParamProductIDFilter$outboundSchema
      .parse(customerPortalSubscriptionsListQueryParamProductIDFilter),
  );
}

/** @internal */
export type CustomerPortalSubscriptionsListRequest$Outbound = {
  product_id?: string | Array<string> | null | undefined;
  active?: boolean | null | undefined;
  query?: string | null | undefined;
  page: number;
  limit: number;
  sorting?: Array<string> | null | undefined;
};

/** @internal */
export const CustomerPortalSubscriptionsListRequest$outboundSchema:
  z.ZodMiniType<
    CustomerPortalSubscriptionsListRequest$Outbound,
    CustomerPortalSubscriptionsListRequest
  > = z.pipe(
    z.object({
      productId: z.optional(
        z.nullable(smartUnion([z.string(), z.array(z.string())])),
      ),
      active: z.optional(z.nullable(z.boolean())),
      query: z.optional(z.nullable(z.string())),
      page: z._default(z.int(), 1),
      limit: z._default(z.int(), 10),
      sorting: z.optional(
        z.nullable(z.array(CustomerSubscriptionSortProperty$outboundSchema)),
      ),
    }),
    z.transform((v) => {
      return remap$(v, {
        productId: "product_id",
      });
    }),
  );

export function customerPortalSubscriptionsListRequestToJSON(
  customerPortalSubscriptionsListRequest:
    CustomerPortalSubscriptionsListRequest,
): string {
  return JSON.stringify(
    CustomerPortalSubscriptionsListRequest$outboundSchema.parse(
      customerPortalSubscriptionsListRequest,
    ),
  );
}

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

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