/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v3";
import { safeParse } from "../lib/schemas.js";
import { ClosedEnum } from "../types/enums.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { Flag, Flag$inboundSchema } from "./flag.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

/**
 * The state of the flags to retrieve. Defaults to `active`.
 */
export const ListTeamFlagsQueryParamState = {
  Active: "active",
  Archived: "archived",
} as const;
/**
 * The state of the flags to retrieve. Defaults to `active`.
 */
export type ListTeamFlagsQueryParamState = ClosedEnum<
  typeof ListTeamFlagsQueryParamState
>;

/**
 * The kind of flags to retrieve.
 */
export const ListTeamFlagsQueryParamKind = {
  Boolean: "boolean",
  String: "string",
  Number: "number",
  Json: "json",
} as const;
/**
 * The kind of flags to retrieve.
 */
export type ListTeamFlagsQueryParamKind = ClosedEnum<
  typeof ListTeamFlagsQueryParamKind
>;

export type ListTeamFlagsRequest = {
  /**
   * The state of the flags to retrieve. Defaults to `active`.
   */
  state?: ListTeamFlagsQueryParamState | undefined;
  /**
   * Deprecated. Whether to include creator metadata in each flag in the response. Resolve creator identity client-side (e.g. via the team members endpoint) instead; this parameter will be removed in a future release.
   */
  withMetadata?: boolean | undefined;
  /**
   * Maximum number of flags to return.
   */
  limit?: number | undefined;
  /**
   * Pagination cursor to continue from.
   */
  cursor?: string | undefined;
  /**
   * Search flags by their slug or description. Case-insensitive.
   */
  search?: string | undefined;
  /**
   * The kind of flags to retrieve.
   */
  kind?: ListTeamFlagsQueryParamKind | undefined;
  /**
   * Filter flags by tag. Repeat the parameter for multiple tags (all must match).
   */
  tags?: Array<string> | undefined;
  /**
   * The Team identifier to perform the request on behalf of.
   */
  teamId: string;
  /**
   * The Team slug to perform the request on behalf of.
   */
  slug?: string | undefined;
};

export type ListTeamFlagsPagination = {
  next: string | null;
};

export type ListTeamFlagsResponseBody = {
  data: Array<Flag>;
  pagination: ListTeamFlagsPagination;
};

/** @internal */
export const ListTeamFlagsQueryParamState$outboundSchema: z.ZodNativeEnum<
  typeof ListTeamFlagsQueryParamState
> = z.nativeEnum(ListTeamFlagsQueryParamState);

/** @internal */
export const ListTeamFlagsQueryParamKind$outboundSchema: z.ZodNativeEnum<
  typeof ListTeamFlagsQueryParamKind
> = z.nativeEnum(ListTeamFlagsQueryParamKind);

/** @internal */
export type ListTeamFlagsRequest$Outbound = {
  state?: string | undefined;
  withMetadata?: boolean | undefined;
  limit: number;
  cursor?: string | undefined;
  search?: string | undefined;
  kind?: string | undefined;
  tags?: Array<string> | undefined;
  teamId: string;
  slug?: string | undefined;
};

/** @internal */
export const ListTeamFlagsRequest$outboundSchema: z.ZodType<
  ListTeamFlagsRequest$Outbound,
  z.ZodTypeDef,
  ListTeamFlagsRequest
> = z.object({
  state: ListTeamFlagsQueryParamState$outboundSchema.optional(),
  withMetadata: z.boolean().optional(),
  limit: z.number().int().default(20),
  cursor: z.string().optional(),
  search: z.string().optional(),
  kind: ListTeamFlagsQueryParamKind$outboundSchema.optional(),
  tags: z.array(z.string()).optional(),
  teamId: z.string(),
  slug: z.string().optional(),
});

export function listTeamFlagsRequestToJSON(
  listTeamFlagsRequest: ListTeamFlagsRequest,
): string {
  return JSON.stringify(
    ListTeamFlagsRequest$outboundSchema.parse(listTeamFlagsRequest),
  );
}

/** @internal */
export const ListTeamFlagsPagination$inboundSchema: z.ZodType<
  ListTeamFlagsPagination,
  z.ZodTypeDef,
  unknown
> = z.object({
  next: types.nullable(types.string()),
});

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

/** @internal */
export const ListTeamFlagsResponseBody$inboundSchema: z.ZodType<
  ListTeamFlagsResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  data: z.array(Flag$inboundSchema),
  pagination: z.lazy(() => ListTeamFlagsPagination$inboundSchema),
});

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