/*
 * 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 {
  ListResourcePayment,
  ListResourcePayment$inboundSchema,
} from "../components/listresourcepayment.js";
import {
  PaymentSortProperty,
  PaymentSortProperty$outboundSchema,
} from "../components/paymentsortproperty.js";
import {
  PaymentStatus,
  PaymentStatus$outboundSchema,
} from "../components/paymentstatus.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

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

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

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

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

/**
 * Filter by payment status.
 */
export type PaymentsListQueryParamStatusFilter =
  | PaymentStatus
  | Array<PaymentStatus>;

/**
 * Filter by payment method.
 */
export type MethodFilter = string | Array<string>;

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

export type PaymentsListRequest = {
  /**
   * Filter by organization ID.
   */
  organizationId?: 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 customer ID.
   */
  customerId?: string | Array<string> | null | undefined;
  /**
   * Filter by payment status.
   */
  status?: PaymentStatus | Array<PaymentStatus> | null | undefined;
  /**
   * Filter by payment method.
   */
  method?: string | Array<string> | null | undefined;
  /**
   * Filter by customer email.
   */
  customerEmail?: 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<PaymentSortProperty> | null | undefined;
};

export type PaymentsListResponse = {
  result: ListResourcePayment;
};

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

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

export function paymentsListQueryParamOrganizationIDFilterToJSON(
  paymentsListQueryParamOrganizationIDFilter:
    PaymentsListQueryParamOrganizationIDFilter,
): string {
  return JSON.stringify(
    PaymentsListQueryParamOrganizationIDFilter$outboundSchema.parse(
      paymentsListQueryParamOrganizationIDFilter,
    ),
  );
}

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

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

export function paymentsListQueryParamCheckoutIDFilterToJSON(
  paymentsListQueryParamCheckoutIDFilter:
    PaymentsListQueryParamCheckoutIDFilter,
): string {
  return JSON.stringify(
    PaymentsListQueryParamCheckoutIDFilter$outboundSchema.parse(
      paymentsListQueryParamCheckoutIDFilter,
    ),
  );
}

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

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

export function paymentsListQueryParamOrderIDFilterToJSON(
  paymentsListQueryParamOrderIDFilter: PaymentsListQueryParamOrderIDFilter,
): string {
  return JSON.stringify(
    PaymentsListQueryParamOrderIDFilter$outboundSchema.parse(
      paymentsListQueryParamOrderIDFilter,
    ),
  );
}

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

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

export function paymentsListQueryParamCustomerIDFilterToJSON(
  paymentsListQueryParamCustomerIDFilter:
    PaymentsListQueryParamCustomerIDFilter,
): string {
  return JSON.stringify(
    PaymentsListQueryParamCustomerIDFilter$outboundSchema.parse(
      paymentsListQueryParamCustomerIDFilter,
    ),
  );
}

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

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

export function paymentsListQueryParamStatusFilterToJSON(
  paymentsListQueryParamStatusFilter: PaymentsListQueryParamStatusFilter,
): string {
  return JSON.stringify(
    PaymentsListQueryParamStatusFilter$outboundSchema.parse(
      paymentsListQueryParamStatusFilter,
    ),
  );
}

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

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

export function methodFilterToJSON(methodFilter: MethodFilter): string {
  return JSON.stringify(MethodFilter$outboundSchema.parse(methodFilter));
}

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

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

export function customerEmailFilterToJSON(
  customerEmailFilter: CustomerEmailFilter,
): string {
  return JSON.stringify(
    CustomerEmailFilter$outboundSchema.parse(customerEmailFilter),
  );
}

/** @internal */
export type PaymentsListRequest$Outbound = {
  organization_id?: string | Array<string> | null | undefined;
  checkout_id?: string | Array<string> | null | undefined;
  order_id?: string | Array<string> | null | undefined;
  customer_id?: string | Array<string> | null | undefined;
  status?: string | Array<string> | null | undefined;
  method?: string | Array<string> | null | undefined;
  customer_email?: string | Array<string> | null | undefined;
  page: number;
  limit: number;
  sorting?: Array<string> | null | undefined;
};

/** @internal */
export const PaymentsListRequest$outboundSchema: z.ZodMiniType<
  PaymentsListRequest$Outbound,
  PaymentsListRequest
> = z.pipe(
  z.object({
    organizationId: 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())])),
    ),
    customerId: z.optional(
      z.nullable(smartUnion([z.string(), z.array(z.string())])),
    ),
    status: z.optional(
      z.nullable(
        smartUnion([
          PaymentStatus$outboundSchema,
          z.array(PaymentStatus$outboundSchema),
        ]),
      ),
    ),
    method: z.optional(
      z.nullable(smartUnion([z.string(), z.array(z.string())])),
    ),
    customerEmail: 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(PaymentSortProperty$outboundSchema)),
    ),
  }),
  z.transform((v) => {
    return remap$(v, {
      organizationId: "organization_id",
      checkoutId: "checkout_id",
      orderId: "order_id",
      customerId: "customer_id",
      customerEmail: "customer_email",
    });
  }),
);

export function paymentsListRequestToJSON(
  paymentsListRequest: PaymentsListRequest,
): string {
  return JSON.stringify(
    PaymentsListRequest$outboundSchema.parse(paymentsListRequest),
  );
}

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

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