/*
 * 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 {
  ListResourceBenefitGrant,
  ListResourceBenefitGrant$inboundSchema,
} from "../components/listresourcebenefitgrant.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

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

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

export type BenefitsGrantsRequest = {
  id: string;
  /**
   * Filter by granted status. If `true`, only granted benefits will be returned. If `false`, only revoked benefits will be returned.
   */
  isGranted?: boolean | null | undefined;
  /**
   * Filter by customer.
   */
  customerId?: string | Array<string> | null | undefined;
  /**
   * Filter by member.
   */
  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;
};

export type BenefitsGrantsResponse = {
  result: ListResourceBenefitGrant;
};

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

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

export function queryParamCustomerIDFilterToJSON(
  queryParamCustomerIDFilter: QueryParamCustomerIDFilter,
): string {
  return JSON.stringify(
    QueryParamCustomerIDFilter$outboundSchema.parse(queryParamCustomerIDFilter),
  );
}

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

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

export function memberIDFilterToJSON(memberIDFilter: MemberIDFilter): string {
  return JSON.stringify(MemberIDFilter$outboundSchema.parse(memberIDFilter));
}

/** @internal */
export type BenefitsGrantsRequest$Outbound = {
  id: string;
  is_granted?: boolean | null | undefined;
  customer_id?: string | Array<string> | null | undefined;
  member_id?: string | Array<string> | null | undefined;
  page: number;
  limit: number;
};

/** @internal */
export const BenefitsGrantsRequest$outboundSchema: z.ZodMiniType<
  BenefitsGrantsRequest$Outbound,
  BenefitsGrantsRequest
> = z.pipe(
  z.object({
    id: z.string(),
    isGranted: z.optional(z.nullable(z.boolean())),
    customerId: 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),
  }),
  z.transform((v) => {
    return remap$(v, {
      isGranted: "is_granted",
      customerId: "customer_id",
      memberId: "member_id",
    });
  }),
);

export function benefitsGrantsRequestToJSON(
  benefitsGrantsRequest: BenefitsGrantsRequest,
): string {
  return JSON.stringify(
    BenefitsGrantsRequest$outboundSchema.parse(benefitsGrantsRequest),
  );
}

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

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