/*
 * 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 {
  CheckoutSortProperty,
  CheckoutSortProperty$outboundSchema,
} from "../components/checkoutsortproperty.js";
import {
  CheckoutStatus,
  CheckoutStatus$outboundSchema,
} from "../components/checkoutstatus.js";
import {
  ListResourceCheckout,
  ListResourceCheckout$inboundSchema,
} from "../components/listresourcecheckout.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

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

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

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

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

/**
 * Filter by checkout session status.
 */
export type CheckoutsListQueryParamStatusFilter =
  | CheckoutStatus
  | Array<CheckoutStatus>;

export type CheckoutsListRequest = {
  /**
   * Filter by organization ID.
   */
  organizationId?: string | Array<string> | null | undefined;
  /**
   * Filter by product ID.
   */
  productId?: string | Array<string> | null | undefined;
  /**
   * Filter by customer ID.
   */
  customerId?: string | Array<string> | null | undefined;
  /**
   * Filter by customer external ID.
   */
  externalCustomerId?: string | Array<string> | null | undefined;
  /**
   * Filter by checkout session status.
   */
  status?: CheckoutStatus | Array<CheckoutStatus> | null | undefined;
  /**
   * Filter by customer email.
   */
  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<CheckoutSortProperty> | null | undefined;
};

export type CheckoutsListResponse = {
  result: ListResourceCheckout;
};

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

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

export function checkoutsListQueryParamOrganizationIDFilterToJSON(
  checkoutsListQueryParamOrganizationIDFilter:
    CheckoutsListQueryParamOrganizationIDFilter,
): string {
  return JSON.stringify(
    CheckoutsListQueryParamOrganizationIDFilter$outboundSchema.parse(
      checkoutsListQueryParamOrganizationIDFilter,
    ),
  );
}

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

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

export function checkoutsListQueryParamProductIDFilterToJSON(
  checkoutsListQueryParamProductIDFilter:
    CheckoutsListQueryParamProductIDFilter,
): string {
  return JSON.stringify(
    CheckoutsListQueryParamProductIDFilter$outboundSchema.parse(
      checkoutsListQueryParamProductIDFilter,
    ),
  );
}

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

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

export function checkoutsListQueryParamCustomerIDFilterToJSON(
  checkoutsListQueryParamCustomerIDFilter:
    CheckoutsListQueryParamCustomerIDFilter,
): string {
  return JSON.stringify(
    CheckoutsListQueryParamCustomerIDFilter$outboundSchema.parse(
      checkoutsListQueryParamCustomerIDFilter,
    ),
  );
}

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

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

export function checkoutsListQueryParamExternalCustomerIDFilterToJSON(
  checkoutsListQueryParamExternalCustomerIDFilter:
    CheckoutsListQueryParamExternalCustomerIDFilter,
): string {
  return JSON.stringify(
    CheckoutsListQueryParamExternalCustomerIDFilter$outboundSchema.parse(
      checkoutsListQueryParamExternalCustomerIDFilter,
    ),
  );
}

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

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

export function checkoutsListQueryParamStatusFilterToJSON(
  checkoutsListQueryParamStatusFilter: CheckoutsListQueryParamStatusFilter,
): string {
  return JSON.stringify(
    CheckoutsListQueryParamStatusFilter$outboundSchema.parse(
      checkoutsListQueryParamStatusFilter,
    ),
  );
}

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

/** @internal */
export const CheckoutsListRequest$outboundSchema: z.ZodMiniType<
  CheckoutsListRequest$Outbound,
  CheckoutsListRequest
> = z.pipe(
  z.object({
    organizationId: z.optional(
      z.nullable(smartUnion([z.string(), z.array(z.string())])),
    ),
    productId: 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())])),
    ),
    status: z.optional(
      z.nullable(
        smartUnion([
          CheckoutStatus$outboundSchema,
          z.array(CheckoutStatus$outboundSchema),
        ]),
      ),
    ),
    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(CheckoutSortProperty$outboundSchema)),
    ),
  }),
  z.transform((v) => {
    return remap$(v, {
      organizationId: "organization_id",
      productId: "product_id",
      customerId: "customer_id",
      externalCustomerId: "external_customer_id",
    });
  }),
);

export function checkoutsListRequestToJSON(
  checkoutsListRequest: CheckoutsListRequest,
): string {
  return JSON.stringify(
    CheckoutsListRequest$outboundSchema.parse(checkoutsListRequest),
  );
}

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

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