/*
 * 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 {
  ListResourceOrganization,
  ListResourceOrganization$inboundSchema,
} from "../components/listresourceorganization.js";
import {
  OrganizationSortProperty,
  OrganizationSortProperty$outboundSchema,
} from "../components/organizationsortproperty.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type OrganizationsListRequest = {
  /**
   * Filter by slug.
   */
  slug?: 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<OrganizationSortProperty> | null | undefined;
};

export type OrganizationsListResponse = {
  result: ListResourceOrganization;
};

/** @internal */
export type OrganizationsListRequest$Outbound = {
  slug?: string | null | undefined;
  page: number;
  limit: number;
  sorting?: Array<string> | null | undefined;
};

/** @internal */
export const OrganizationsListRequest$outboundSchema: z.ZodMiniType<
  OrganizationsListRequest$Outbound,
  OrganizationsListRequest
> = z.object({
  slug: 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(OrganizationSortProperty$outboundSchema)),
  ),
});

export function organizationsListRequestToJSON(
  organizationsListRequest: OrganizationsListRequest,
): string {
  return JSON.stringify(
    OrganizationsListRequest$outboundSchema.parse(organizationsListRequest),
  );
}

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

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