/*
 * 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 {
  BenefitType,
  BenefitType$outboundSchema,
} from "../components/benefittype.js";
import {
  CustomerBenefitGrantSortProperty,
  CustomerBenefitGrantSortProperty$outboundSchema,
} from "../components/customerbenefitgrantsortproperty.js";
import {
  ListResourceCustomerBenefitGrant,
  ListResourceCustomerBenefitGrant$inboundSchema,
} from "../components/listresourcecustomerbenefitgrant.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

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

/**
 * Filter by benefit type.
 */
export type QueryParamBenefitTypeFilter = BenefitType | Array<BenefitType>;

/**
 * Filter by benefit ID.
 */
export type CustomerPortalBenefitGrantsListQueryParamBenefitIDFilter =
  | string
  | Array<string>;

/**
 * Filter by checkout ID.
 */
export type QueryParamCheckoutIDFilter = string | Array<string>;

/**
 * Filter by order ID.
 */
export type CustomerPortalBenefitGrantsListQueryParamOrderIDFilter =
  | string
  | Array<string>;

/**
 * Filter by subscription ID.
 */
export type CustomerPortalBenefitGrantsListQueryParamSubscriptionIDFilter =
  | string
  | Array<string>;

/**
 * Filter by member ID.
 */
export type QueryParamMemberIDFilter = string | Array<string>;

export type CustomerPortalBenefitGrantsListRequest = {
  /**
   * Filter by benefit description.
   */
  query?: string | null | undefined;
  /**
   * Filter by benefit type.
   */
  typeFilter?: BenefitType | Array<BenefitType> | null | undefined;
  /**
   * Filter by benefit ID.
   */
  benefitId?: string | Array<string> | null | undefined;
  /**
   * Filter by checkout ID.
   */
  checkoutId?: string | Array<string> | null | undefined;
  /**
   * Filter by order ID.
   */
  orderId?: string | Array<string> | null | undefined;
  /**
   * Filter by subscription ID.
   */
  subscriptionId?: string | Array<string> | null | undefined;
  /**
   * Filter by member ID.
   */
  memberId?: 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<CustomerBenefitGrantSortProperty> | null | undefined;
};

export type CustomerPortalBenefitGrantsListResponse = {
  result: ListResourceCustomerBenefitGrant;
};

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

/** @internal */
export const CustomerPortalBenefitGrantsListSecurity$outboundSchema:
  z.ZodMiniType<
    CustomerPortalBenefitGrantsListSecurity$Outbound,
    CustomerPortalBenefitGrantsListSecurity
  > = 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 customerPortalBenefitGrantsListSecurityToJSON(
  customerPortalBenefitGrantsListSecurity:
    CustomerPortalBenefitGrantsListSecurity,
): string {
  return JSON.stringify(
    CustomerPortalBenefitGrantsListSecurity$outboundSchema.parse(
      customerPortalBenefitGrantsListSecurity,
    ),
  );
}

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

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

export function queryParamBenefitTypeFilterToJSON(
  queryParamBenefitTypeFilter: QueryParamBenefitTypeFilter,
): string {
  return JSON.stringify(
    QueryParamBenefitTypeFilter$outboundSchema.parse(
      queryParamBenefitTypeFilter,
    ),
  );
}

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

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

export function customerPortalBenefitGrantsListQueryParamBenefitIDFilterToJSON(
  customerPortalBenefitGrantsListQueryParamBenefitIDFilter:
    CustomerPortalBenefitGrantsListQueryParamBenefitIDFilter,
): string {
  return JSON.stringify(
    CustomerPortalBenefitGrantsListQueryParamBenefitIDFilter$outboundSchema
      .parse(customerPortalBenefitGrantsListQueryParamBenefitIDFilter),
  );
}

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

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

export function queryParamCheckoutIDFilterToJSON(
  queryParamCheckoutIDFilter: QueryParamCheckoutIDFilter,
): string {
  return JSON.stringify(
    QueryParamCheckoutIDFilter$outboundSchema.parse(queryParamCheckoutIDFilter),
  );
}

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

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

export function customerPortalBenefitGrantsListQueryParamOrderIDFilterToJSON(
  customerPortalBenefitGrantsListQueryParamOrderIDFilter:
    CustomerPortalBenefitGrantsListQueryParamOrderIDFilter,
): string {
  return JSON.stringify(
    CustomerPortalBenefitGrantsListQueryParamOrderIDFilter$outboundSchema.parse(
      customerPortalBenefitGrantsListQueryParamOrderIDFilter,
    ),
  );
}

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

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

export function customerPortalBenefitGrantsListQueryParamSubscriptionIDFilterToJSON(
  customerPortalBenefitGrantsListQueryParamSubscriptionIDFilter:
    CustomerPortalBenefitGrantsListQueryParamSubscriptionIDFilter,
): string {
  return JSON.stringify(
    CustomerPortalBenefitGrantsListQueryParamSubscriptionIDFilter$outboundSchema
      .parse(customerPortalBenefitGrantsListQueryParamSubscriptionIDFilter),
  );
}

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

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

export function queryParamMemberIDFilterToJSON(
  queryParamMemberIDFilter: QueryParamMemberIDFilter,
): string {
  return JSON.stringify(
    QueryParamMemberIDFilter$outboundSchema.parse(queryParamMemberIDFilter),
  );
}

/** @internal */
export type CustomerPortalBenefitGrantsListRequest$Outbound = {
  query?: string | null | undefined;
  type_filter?: string | Array<string> | null | undefined;
  benefit_id?: string | Array<string> | null | undefined;
  checkout_id?: string | Array<string> | null | undefined;
  order_id?: string | Array<string> | null | undefined;
  subscription_id?: string | Array<string> | null | undefined;
  member_id?: string | Array<string> | null | undefined;
  page: number;
  limit: number;
  sorting?: Array<string> | null | undefined;
};

/** @internal */
export const CustomerPortalBenefitGrantsListRequest$outboundSchema:
  z.ZodMiniType<
    CustomerPortalBenefitGrantsListRequest$Outbound,
    CustomerPortalBenefitGrantsListRequest
  > = z.pipe(
    z.object({
      query: z.optional(z.nullable(z.string())),
      typeFilter: z.optional(
        z.nullable(
          smartUnion([
            BenefitType$outboundSchema,
            z.array(BenefitType$outboundSchema),
          ]),
        ),
      ),
      benefitId: z.optional(
        z.nullable(smartUnion([z.string(), z.array(z.string())])),
      ),
      checkoutId: z.optional(
        z.nullable(smartUnion([z.string(), z.array(z.string())])),
      ),
      orderId: z.optional(
        z.nullable(smartUnion([z.string(), z.array(z.string())])),
      ),
      subscriptionId: z.optional(
        z.nullable(smartUnion([z.string(), z.array(z.string())])),
      ),
      memberId: 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(CustomerBenefitGrantSortProperty$outboundSchema)),
      ),
    }),
    z.transform((v) => {
      return remap$(v, {
        typeFilter: "type_filter",
        benefitId: "benefit_id",
        checkoutId: "checkout_id",
        orderId: "order_id",
        subscriptionId: "subscription_id",
        memberId: "member_id",
      });
    }),
  );

export function customerPortalBenefitGrantsListRequestToJSON(
  customerPortalBenefitGrantsListRequest:
    CustomerPortalBenefitGrantsListRequest,
): string {
  return JSON.stringify(
    CustomerPortalBenefitGrantsListRequest$outboundSchema.parse(
      customerPortalBenefitGrantsListRequest,
    ),
  );
}

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

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