/*
 * 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 {
  LicenseKeyStatus,
  LicenseKeyStatus$outboundSchema,
} from "../components/licensekeystatus.js";
import {
  ListResourceLicenseKeyRead,
  ListResourceLicenseKeyRead$inboundSchema,
} from "../components/listresourcelicensekeyread.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

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

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

/**
 * Filter by license key status.
 */
export type LicenseKeyStatusFilter = LicenseKeyStatus | Array<LicenseKeyStatus>;

export type LicenseKeysListRequest = {
  /**
   * Filter by organization ID.
   */
  organizationId?: string | Array<string> | null | undefined;
  /**
   * Filter by benefit ID.
   */
  benefitId?: string | Array<string> | null | undefined;
  /**
   * Filter by license key status.
   */
  status?: LicenseKeyStatus | Array<LicenseKeyStatus> | 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 LicenseKeysListResponse = {
  result: ListResourceLicenseKeyRead;
};

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

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

export function licenseKeysListQueryParamOrganizationIDFilterToJSON(
  licenseKeysListQueryParamOrganizationIDFilter:
    LicenseKeysListQueryParamOrganizationIDFilter,
): string {
  return JSON.stringify(
    LicenseKeysListQueryParamOrganizationIDFilter$outboundSchema.parse(
      licenseKeysListQueryParamOrganizationIDFilter,
    ),
  );
}

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

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

export function queryParamBenefitIDFilterToJSON(
  queryParamBenefitIDFilter: QueryParamBenefitIDFilter,
): string {
  return JSON.stringify(
    QueryParamBenefitIDFilter$outboundSchema.parse(queryParamBenefitIDFilter),
  );
}

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

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

export function licenseKeyStatusFilterToJSON(
  licenseKeyStatusFilter: LicenseKeyStatusFilter,
): string {
  return JSON.stringify(
    LicenseKeyStatusFilter$outboundSchema.parse(licenseKeyStatusFilter),
  );
}

/** @internal */
export type LicenseKeysListRequest$Outbound = {
  organization_id?: string | Array<string> | null | undefined;
  benefit_id?: string | Array<string> | null | undefined;
  status?: string | Array<string> | null | undefined;
  page: number;
  limit: number;
};

/** @internal */
export const LicenseKeysListRequest$outboundSchema: z.ZodMiniType<
  LicenseKeysListRequest$Outbound,
  LicenseKeysListRequest
> = z.pipe(
  z.object({
    organizationId: z.optional(
      z.nullable(smartUnion([z.string(), z.array(z.string())])),
    ),
    benefitId: z.optional(
      z.nullable(smartUnion([z.string(), z.array(z.string())])),
    ),
    status: z.optional(
      z.nullable(
        smartUnion([
          LicenseKeyStatus$outboundSchema,
          z.array(LicenseKeyStatus$outboundSchema),
        ]),
      ),
    ),
    page: z._default(z.int(), 1),
    limit: z._default(z.int(), 10),
  }),
  z.transform((v) => {
    return remap$(v, {
      organizationId: "organization_id",
      benefitId: "benefit_id",
    });
  }),
);

export function licenseKeysListRequestToJSON(
  licenseKeysListRequest: LicenseKeysListRequest,
): string {
  return JSON.stringify(
    LicenseKeysListRequest$outboundSchema.parse(licenseKeysListRequest),
  );
}

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

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