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

import * as z from "zod/v3";
import { remap as remap$ } from "../lib/primitives.js";
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 { smartUnion } from "../types/smartUnion.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

export type CreateFlagSegmentLhs2 = {
  type?: any | undefined;
  kind: string;
  attribute: string;
};

export type CreateFlagSegmentLhs1 = {
  type?: any | undefined;
};

export type CreateFlagSegmentLhs =
  | CreateFlagSegmentLhs2
  | CreateFlagSegmentLhs1;

export const CreateFlagSegmentCmp = {
  Eq: "eq",
  NotEq: "!eq",
  OneOf: "oneOf",
  NotOneOf: "!oneOf",
  ContainsAllOf: "containsAllOf",
  ContainsAnyOf: "containsAnyOf",
  ContainsNoneOf: "containsNoneOf",
  StartsWith: "startsWith",
  NotStartsWith: "!startsWith",
  EndsWith: "endsWith",
  NotEndsWith: "!endsWith",
  Contains: "contains",
  NotContains: "!contains",
  Ex: "ex",
  NotEx: "!ex",
  Gt: "gt",
  Gte: "gte",
  Lt: "lt",
  Lte: "lte",
  Regex: "regex",
  NotRegex: "!regex",
  Before: "before",
  After: "after",
} as const;
export type CreateFlagSegmentCmp = ClosedEnum<typeof CreateFlagSegmentCmp>;

export type CreateFlagSegmentRhs2 = {
  type?: any | undefined;
  pattern: string;
  flags: string;
};

export const CreateFlagSegmentRhsType = {
  ListInline: "list/inline",
  List: "list",
} as const;
export type CreateFlagSegmentRhsType = ClosedEnum<
  typeof CreateFlagSegmentRhsType
>;

export type CreateFlagSegmentItems2 = {
  label?: string | undefined;
  note?: string | undefined;
  value: string;
};

export type CreateFlagSegmentItems1 = {
  label?: string | undefined;
  note?: string | undefined;
  value: number;
};

export type CreateFlagSegmentRhsItems =
  | CreateFlagSegmentItems1
  | CreateFlagSegmentItems2;

export type CreateFlagSegmentRhs1 = {
  type: CreateFlagSegmentRhsType;
  items: Array<CreateFlagSegmentItems1 | CreateFlagSegmentItems2>;
};

export type CreateFlagSegmentRhs =
  | CreateFlagSegmentRhs2
  | CreateFlagSegmentRhs1
  | string
  | number
  | boolean;

export type CreateFlagSegmentCmpOptions = {
  ignoreCase?: boolean | undefined;
};

export type CreateFlagSegmentConditions = {
  lhs: CreateFlagSegmentLhs2 | CreateFlagSegmentLhs1;
  cmp: CreateFlagSegmentCmp;
  rhs?:
    | CreateFlagSegmentRhs2
    | CreateFlagSegmentRhs1
    | string
    | number
    | boolean
    | undefined;
  cmpOptions?: CreateFlagSegmentCmpOptions | undefined;
};

export type CreateFlagSegmentOutcomeBase = {
  type?: any | undefined;
  kind: string;
  attribute: string;
};

export type CreateFlagSegmentOutcome2 = {
  type?: any | undefined;
  base: CreateFlagSegmentOutcomeBase;
  passPromille: number;
};

export type CreateFlagSegmentOutcome1 = {
  type?: any | undefined;
};

export type CreateFlagSegmentOutcome =
  | CreateFlagSegmentOutcome2
  | CreateFlagSegmentOutcome1;

export type CreateFlagSegmentRules = {
  id: string;
  conditions: Array<CreateFlagSegmentConditions>;
  outcome: CreateFlagSegmentOutcome2 | CreateFlagSegmentOutcome1;
};

export type CreateFlagSegmentInclude = {
  note?: string | undefined;
  value: string;
};

export type CreateFlagSegmentExclude = {
  note?: string | undefined;
  value: string;
};

/**
 * The data of the segment
 */
export type CreateFlagSegmentData = {
  rules?: Array<CreateFlagSegmentRules> | undefined;
  include?:
    | { [k: string]: { [k: string]: Array<CreateFlagSegmentInclude> } }
    | undefined;
  exclude?:
    | { [k: string]: { [k: string]: Array<CreateFlagSegmentExclude> } }
    | undefined;
};

export type CreateFlagSegmentRequestBody = {
  slug: string;
  /**
   * The entity who created the segment
   */
  createdBy?: string | undefined;
  label: string;
  description?: string | undefined;
  /**
   * The data of the segment
   */
  data: CreateFlagSegmentData;
  hint: string;
};

export type CreateFlagSegmentRequest = {
  /**
   * The project id or name
   */
  projectIdOrName: string;
  /**
   * The Team identifier to perform the request on behalf of.
   */
  teamId?: string | undefined;
  /**
   * The Team slug to perform the request on behalf of.
   */
  slug?: string | undefined;
  requestBody?: CreateFlagSegmentRequestBody | undefined;
};

export const CreateFlagSegmentOutcomeFeatureFlagsResponseType = {
  Entity: "entity",
} as const;
export type CreateFlagSegmentOutcomeFeatureFlagsResponseType = ClosedEnum<
  typeof CreateFlagSegmentOutcomeFeatureFlagsResponseType
>;

export type CreateFlagSegmentOutcomeFeatureFlagsBase = {
  type: CreateFlagSegmentOutcomeFeatureFlagsResponseType;
  kind: string;
  attribute: string;
};

export type CreateFlagSegmentOutcomeFeatureFlags2 = {
  type: "split";
  base: CreateFlagSegmentOutcomeFeatureFlagsBase;
  passPromille: number;
};

export type CreateFlagSegmentOutcomeFeatureFlags1 = {
  type: "all";
};

export type CreateFlagSegmentFeatureFlagsOutcome =
  | CreateFlagSegmentOutcomeFeatureFlags1
  | CreateFlagSegmentOutcomeFeatureFlags2;

export const CreateFlagSegmentRhsFeatureFlagsResponseType = {
  Regex: "regex",
} as const;
export type CreateFlagSegmentRhsFeatureFlagsResponseType = ClosedEnum<
  typeof CreateFlagSegmentRhsFeatureFlagsResponseType
>;

export type CreateFlagSegmentRhs4 = {
  type: CreateFlagSegmentRhsFeatureFlagsResponseType;
  pattern: string;
  flags: string;
};

export const CreateFlagSegmentRhsFeatureFlagsType = {
  List: "list",
  ListInline: "list/inline",
} as const;
export type CreateFlagSegmentRhsFeatureFlagsType = ClosedEnum<
  typeof CreateFlagSegmentRhsFeatureFlagsType
>;

export type CreateFlagSegmentItemsFeatureFlags2 = {
  label?: string | undefined;
  note?: string | undefined;
  value: string;
};

export type CreateFlagSegmentItemsFeatureFlags1 = {
  label?: string | undefined;
  note?: string | undefined;
  value: number;
};

export type CreateFlagSegmentRhsFeatureFlagsItems =
  | CreateFlagSegmentItemsFeatureFlags1
  | CreateFlagSegmentItemsFeatureFlags2;

export type CreateFlagSegmentRhs3 = {
  type: CreateFlagSegmentRhsFeatureFlagsType;
  items: Array<
    CreateFlagSegmentItemsFeatureFlags1 | CreateFlagSegmentItemsFeatureFlags2
  >;
};

export type CreateFlagSegmentFeatureFlagsRhs =
  | CreateFlagSegmentRhs4
  | CreateFlagSegmentRhs3
  | string
  | number
  | boolean;

export type CreateFlagSegmentFeatureFlagsCmpOptions = {
  ignoreCase?: boolean | undefined;
};

export type CreateFlagSegmentLhsFeatureFlags2 = {
  type: "entity";
  kind: string;
  attribute: string;
};

export type CreateFlagSegmentLhsFeatureFlags1 = {
  type: "segment";
};

export type CreateFlagSegmentFeatureFlagsLhs =
  | CreateFlagSegmentLhsFeatureFlags1
  | CreateFlagSegmentLhsFeatureFlags2;

export const CreateFlagSegmentFeatureFlagsCmp = {
  NotContains: "!contains",
  NotEndsWith: "!endsWith",
  NotEq: "!eq",
  NotEx: "!ex",
  NotOneOf: "!oneOf",
  NotRegex: "!regex",
  NotStartsWith: "!startsWith",
  After: "after",
  Before: "before",
  Contains: "contains",
  ContainsAllOf: "containsAllOf",
  ContainsAnyOf: "containsAnyOf",
  ContainsNoneOf: "containsNoneOf",
  EndsWith: "endsWith",
  Eq: "eq",
  Ex: "ex",
  Gt: "gt",
  Gte: "gte",
  Lt: "lt",
  Lte: "lte",
  OneOf: "oneOf",
  Regex: "regex",
  StartsWith: "startsWith",
} as const;
export type CreateFlagSegmentFeatureFlagsCmp = ClosedEnum<
  typeof CreateFlagSegmentFeatureFlagsCmp
>;

export type CreateFlagSegmentFeatureFlagsConditions = {
  rhs?:
    | CreateFlagSegmentRhs4
    | CreateFlagSegmentRhs3
    | string
    | number
    | boolean
    | undefined;
  cmpOptions?: CreateFlagSegmentFeatureFlagsCmpOptions | undefined;
  lhs: CreateFlagSegmentLhsFeatureFlags1 | CreateFlagSegmentLhsFeatureFlags2;
  cmp: CreateFlagSegmentFeatureFlagsCmp;
};

export type CreateFlagSegmentFeatureFlagsRules = {
  id: string;
  outcome:
    | CreateFlagSegmentOutcomeFeatureFlags1
    | CreateFlagSegmentOutcomeFeatureFlags2;
  conditions: Array<CreateFlagSegmentFeatureFlagsConditions>;
};

export type CreateFlagSegmentFeatureFlagsInclude = {
  note?: string | undefined;
  value: string;
};

export type CreateFlagSegmentFeatureFlagsExclude = {
  note?: string | undefined;
  value: string;
};

export type CreateFlagSegmentFeatureFlagsData = {
  rules?: Array<CreateFlagSegmentFeatureFlagsRules> | undefined;
  include?: {
    [k: string]: { [k: string]: Array<CreateFlagSegmentFeatureFlagsInclude> };
  } | undefined;
  exclude?: {
    [k: string]: { [k: string]: Array<CreateFlagSegmentFeatureFlagsExclude> };
  } | undefined;
};

export const CreateFlagSegmentTypeName = {
  Segment: "segment",
} as const;
export type CreateFlagSegmentTypeName = ClosedEnum<
  typeof CreateFlagSegmentTypeName
>;

export type CreateFlagSegmentResponseBody = {
  description?: string | undefined;
  createdBy?: string | undefined;
  usedByFlags?: Array<string> | undefined;
  usedBySegments?: Array<string> | undefined;
  data: CreateFlagSegmentFeatureFlagsData;
  id: string;
  label: string;
  slug: string;
  createdAt: number;
  updatedAt: number;
  projectId: string;
  typeName: CreateFlagSegmentTypeName;
  hint: string;
};

/** @internal */
export type CreateFlagSegmentLhs2$Outbound = {
  type?: any | undefined;
  kind: string;
  attribute: string;
};

/** @internal */
export const CreateFlagSegmentLhs2$outboundSchema: z.ZodType<
  CreateFlagSegmentLhs2$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentLhs2
> = z.object({
  type: z.any().optional(),
  kind: z.string(),
  attribute: z.string(),
});

export function createFlagSegmentLhs2ToJSON(
  createFlagSegmentLhs2: CreateFlagSegmentLhs2,
): string {
  return JSON.stringify(
    CreateFlagSegmentLhs2$outboundSchema.parse(createFlagSegmentLhs2),
  );
}

/** @internal */
export type CreateFlagSegmentLhs1$Outbound = {
  type?: any | undefined;
};

/** @internal */
export const CreateFlagSegmentLhs1$outboundSchema: z.ZodType<
  CreateFlagSegmentLhs1$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentLhs1
> = z.object({
  type: z.any().optional(),
});

export function createFlagSegmentLhs1ToJSON(
  createFlagSegmentLhs1: CreateFlagSegmentLhs1,
): string {
  return JSON.stringify(
    CreateFlagSegmentLhs1$outboundSchema.parse(createFlagSegmentLhs1),
  );
}

/** @internal */
export type CreateFlagSegmentLhs$Outbound =
  | CreateFlagSegmentLhs2$Outbound
  | CreateFlagSegmentLhs1$Outbound;

/** @internal */
export const CreateFlagSegmentLhs$outboundSchema: z.ZodType<
  CreateFlagSegmentLhs$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentLhs
> = smartUnion([
  z.lazy(() => CreateFlagSegmentLhs2$outboundSchema),
  z.lazy(() => CreateFlagSegmentLhs1$outboundSchema),
]);

export function createFlagSegmentLhsToJSON(
  createFlagSegmentLhs: CreateFlagSegmentLhs,
): string {
  return JSON.stringify(
    CreateFlagSegmentLhs$outboundSchema.parse(createFlagSegmentLhs),
  );
}

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

/** @internal */
export type CreateFlagSegmentRhs2$Outbound = {
  type?: any | undefined;
  pattern: string;
  flags: string;
};

/** @internal */
export const CreateFlagSegmentRhs2$outboundSchema: z.ZodType<
  CreateFlagSegmentRhs2$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentRhs2
> = z.object({
  type: z.any().optional(),
  pattern: z.string(),
  flags: z.string(),
});

export function createFlagSegmentRhs2ToJSON(
  createFlagSegmentRhs2: CreateFlagSegmentRhs2,
): string {
  return JSON.stringify(
    CreateFlagSegmentRhs2$outboundSchema.parse(createFlagSegmentRhs2),
  );
}

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

/** @internal */
export type CreateFlagSegmentItems2$Outbound = {
  label?: string | undefined;
  note?: string | undefined;
  value: string;
};

/** @internal */
export const CreateFlagSegmentItems2$outboundSchema: z.ZodType<
  CreateFlagSegmentItems2$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentItems2
> = z.object({
  label: z.string().optional(),
  note: z.string().optional(),
  value: z.string(),
});

export function createFlagSegmentItems2ToJSON(
  createFlagSegmentItems2: CreateFlagSegmentItems2,
): string {
  return JSON.stringify(
    CreateFlagSegmentItems2$outboundSchema.parse(createFlagSegmentItems2),
  );
}

/** @internal */
export type CreateFlagSegmentItems1$Outbound = {
  label?: string | undefined;
  note?: string | undefined;
  value: number;
};

/** @internal */
export const CreateFlagSegmentItems1$outboundSchema: z.ZodType<
  CreateFlagSegmentItems1$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentItems1
> = z.object({
  label: z.string().optional(),
  note: z.string().optional(),
  value: z.number(),
});

export function createFlagSegmentItems1ToJSON(
  createFlagSegmentItems1: CreateFlagSegmentItems1,
): string {
  return JSON.stringify(
    CreateFlagSegmentItems1$outboundSchema.parse(createFlagSegmentItems1),
  );
}

/** @internal */
export type CreateFlagSegmentRhsItems$Outbound =
  | CreateFlagSegmentItems1$Outbound
  | CreateFlagSegmentItems2$Outbound;

/** @internal */
export const CreateFlagSegmentRhsItems$outboundSchema: z.ZodType<
  CreateFlagSegmentRhsItems$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentRhsItems
> = smartUnion([
  z.lazy(() => CreateFlagSegmentItems1$outboundSchema),
  z.lazy(() => CreateFlagSegmentItems2$outboundSchema),
]);

export function createFlagSegmentRhsItemsToJSON(
  createFlagSegmentRhsItems: CreateFlagSegmentRhsItems,
): string {
  return JSON.stringify(
    CreateFlagSegmentRhsItems$outboundSchema.parse(createFlagSegmentRhsItems),
  );
}

/** @internal */
export type CreateFlagSegmentRhs1$Outbound = {
  type: string;
  items: Array<
    CreateFlagSegmentItems1$Outbound | CreateFlagSegmentItems2$Outbound
  >;
};

/** @internal */
export const CreateFlagSegmentRhs1$outboundSchema: z.ZodType<
  CreateFlagSegmentRhs1$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentRhs1
> = z.object({
  type: CreateFlagSegmentRhsType$outboundSchema,
  items: z.array(
    smartUnion([
      z.lazy(() => CreateFlagSegmentItems1$outboundSchema),
      z.lazy(() => CreateFlagSegmentItems2$outboundSchema),
    ]),
  ),
});

export function createFlagSegmentRhs1ToJSON(
  createFlagSegmentRhs1: CreateFlagSegmentRhs1,
): string {
  return JSON.stringify(
    CreateFlagSegmentRhs1$outboundSchema.parse(createFlagSegmentRhs1),
  );
}

/** @internal */
export type CreateFlagSegmentRhs$Outbound =
  | CreateFlagSegmentRhs2$Outbound
  | CreateFlagSegmentRhs1$Outbound
  | string
  | number
  | boolean;

/** @internal */
export const CreateFlagSegmentRhs$outboundSchema: z.ZodType<
  CreateFlagSegmentRhs$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentRhs
> = smartUnion([
  z.lazy(() => CreateFlagSegmentRhs2$outboundSchema),
  z.lazy(() => CreateFlagSegmentRhs1$outboundSchema),
  z.string(),
  z.number(),
  z.boolean(),
]);

export function createFlagSegmentRhsToJSON(
  createFlagSegmentRhs: CreateFlagSegmentRhs,
): string {
  return JSON.stringify(
    CreateFlagSegmentRhs$outboundSchema.parse(createFlagSegmentRhs),
  );
}

/** @internal */
export type CreateFlagSegmentCmpOptions$Outbound = {
  ignoreCase?: boolean | undefined;
};

/** @internal */
export const CreateFlagSegmentCmpOptions$outboundSchema: z.ZodType<
  CreateFlagSegmentCmpOptions$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentCmpOptions
> = z.object({
  ignoreCase: z.boolean().optional(),
});

export function createFlagSegmentCmpOptionsToJSON(
  createFlagSegmentCmpOptions: CreateFlagSegmentCmpOptions,
): string {
  return JSON.stringify(
    CreateFlagSegmentCmpOptions$outboundSchema.parse(
      createFlagSegmentCmpOptions,
    ),
  );
}

/** @internal */
export type CreateFlagSegmentConditions$Outbound = {
  lhs: CreateFlagSegmentLhs2$Outbound | CreateFlagSegmentLhs1$Outbound;
  cmp: string;
  rhs?:
    | CreateFlagSegmentRhs2$Outbound
    | CreateFlagSegmentRhs1$Outbound
    | string
    | number
    | boolean
    | undefined;
  cmpOptions?: CreateFlagSegmentCmpOptions$Outbound | undefined;
};

/** @internal */
export const CreateFlagSegmentConditions$outboundSchema: z.ZodType<
  CreateFlagSegmentConditions$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentConditions
> = z.object({
  lhs: smartUnion([
    z.lazy(() => CreateFlagSegmentLhs2$outboundSchema),
    z.lazy(() => CreateFlagSegmentLhs1$outboundSchema),
  ]),
  cmp: CreateFlagSegmentCmp$outboundSchema,
  rhs: smartUnion([
    z.lazy(() => CreateFlagSegmentRhs2$outboundSchema),
    z.lazy(() => CreateFlagSegmentRhs1$outboundSchema),
    z.string(),
    z.number(),
    z.boolean(),
  ]).optional(),
  cmpOptions: z.lazy(() => CreateFlagSegmentCmpOptions$outboundSchema)
    .optional(),
});

export function createFlagSegmentConditionsToJSON(
  createFlagSegmentConditions: CreateFlagSegmentConditions,
): string {
  return JSON.stringify(
    CreateFlagSegmentConditions$outboundSchema.parse(
      createFlagSegmentConditions,
    ),
  );
}

/** @internal */
export type CreateFlagSegmentOutcomeBase$Outbound = {
  type?: any | undefined;
  kind: string;
  attribute: string;
};

/** @internal */
export const CreateFlagSegmentOutcomeBase$outboundSchema: z.ZodType<
  CreateFlagSegmentOutcomeBase$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentOutcomeBase
> = z.object({
  type: z.any().optional(),
  kind: z.string(),
  attribute: z.string(),
});

export function createFlagSegmentOutcomeBaseToJSON(
  createFlagSegmentOutcomeBase: CreateFlagSegmentOutcomeBase,
): string {
  return JSON.stringify(
    CreateFlagSegmentOutcomeBase$outboundSchema.parse(
      createFlagSegmentOutcomeBase,
    ),
  );
}

/** @internal */
export type CreateFlagSegmentOutcome2$Outbound = {
  type?: any | undefined;
  base: CreateFlagSegmentOutcomeBase$Outbound;
  passPromille: number;
};

/** @internal */
export const CreateFlagSegmentOutcome2$outboundSchema: z.ZodType<
  CreateFlagSegmentOutcome2$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentOutcome2
> = z.object({
  type: z.any().optional(),
  base: z.lazy(() => CreateFlagSegmentOutcomeBase$outboundSchema),
  passPromille: z.number(),
});

export function createFlagSegmentOutcome2ToJSON(
  createFlagSegmentOutcome2: CreateFlagSegmentOutcome2,
): string {
  return JSON.stringify(
    CreateFlagSegmentOutcome2$outboundSchema.parse(createFlagSegmentOutcome2),
  );
}

/** @internal */
export type CreateFlagSegmentOutcome1$Outbound = {
  type?: any | undefined;
};

/** @internal */
export const CreateFlagSegmentOutcome1$outboundSchema: z.ZodType<
  CreateFlagSegmentOutcome1$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentOutcome1
> = z.object({
  type: z.any().optional(),
});

export function createFlagSegmentOutcome1ToJSON(
  createFlagSegmentOutcome1: CreateFlagSegmentOutcome1,
): string {
  return JSON.stringify(
    CreateFlagSegmentOutcome1$outboundSchema.parse(createFlagSegmentOutcome1),
  );
}

/** @internal */
export type CreateFlagSegmentOutcome$Outbound =
  | CreateFlagSegmentOutcome2$Outbound
  | CreateFlagSegmentOutcome1$Outbound;

/** @internal */
export const CreateFlagSegmentOutcome$outboundSchema: z.ZodType<
  CreateFlagSegmentOutcome$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentOutcome
> = smartUnion([
  z.lazy(() => CreateFlagSegmentOutcome2$outboundSchema),
  z.lazy(() => CreateFlagSegmentOutcome1$outboundSchema),
]);

export function createFlagSegmentOutcomeToJSON(
  createFlagSegmentOutcome: CreateFlagSegmentOutcome,
): string {
  return JSON.stringify(
    CreateFlagSegmentOutcome$outboundSchema.parse(createFlagSegmentOutcome),
  );
}

/** @internal */
export type CreateFlagSegmentRules$Outbound = {
  id: string;
  conditions: Array<CreateFlagSegmentConditions$Outbound>;
  outcome:
    | CreateFlagSegmentOutcome2$Outbound
    | CreateFlagSegmentOutcome1$Outbound;
};

/** @internal */
export const CreateFlagSegmentRules$outboundSchema: z.ZodType<
  CreateFlagSegmentRules$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentRules
> = z.object({
  id: z.string(),
  conditions: z.array(z.lazy(() => CreateFlagSegmentConditions$outboundSchema)),
  outcome: smartUnion([
    z.lazy(() => CreateFlagSegmentOutcome2$outboundSchema),
    z.lazy(() => CreateFlagSegmentOutcome1$outboundSchema),
  ]),
});

export function createFlagSegmentRulesToJSON(
  createFlagSegmentRules: CreateFlagSegmentRules,
): string {
  return JSON.stringify(
    CreateFlagSegmentRules$outboundSchema.parse(createFlagSegmentRules),
  );
}

/** @internal */
export type CreateFlagSegmentInclude$Outbound = {
  note?: string | undefined;
  value: string;
};

/** @internal */
export const CreateFlagSegmentInclude$outboundSchema: z.ZodType<
  CreateFlagSegmentInclude$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentInclude
> = z.object({
  note: z.string().optional(),
  value: z.string(),
});

export function createFlagSegmentIncludeToJSON(
  createFlagSegmentInclude: CreateFlagSegmentInclude,
): string {
  return JSON.stringify(
    CreateFlagSegmentInclude$outboundSchema.parse(createFlagSegmentInclude),
  );
}

/** @internal */
export type CreateFlagSegmentExclude$Outbound = {
  note?: string | undefined;
  value: string;
};

/** @internal */
export const CreateFlagSegmentExclude$outboundSchema: z.ZodType<
  CreateFlagSegmentExclude$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentExclude
> = z.object({
  note: z.string().optional(),
  value: z.string(),
});

export function createFlagSegmentExcludeToJSON(
  createFlagSegmentExclude: CreateFlagSegmentExclude,
): string {
  return JSON.stringify(
    CreateFlagSegmentExclude$outboundSchema.parse(createFlagSegmentExclude),
  );
}

/** @internal */
export type CreateFlagSegmentData$Outbound = {
  rules?: Array<CreateFlagSegmentRules$Outbound> | undefined;
  include?: {
    [k: string]: { [k: string]: Array<CreateFlagSegmentInclude$Outbound> };
  } | undefined;
  exclude?: {
    [k: string]: { [k: string]: Array<CreateFlagSegmentExclude$Outbound> };
  } | undefined;
};

/** @internal */
export const CreateFlagSegmentData$outboundSchema: z.ZodType<
  CreateFlagSegmentData$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentData
> = z.object({
  rules: z.array(z.lazy(() => CreateFlagSegmentRules$outboundSchema))
    .optional(),
  include: z.record(
    z.record(z.array(z.lazy(() => CreateFlagSegmentInclude$outboundSchema))),
  ).optional(),
  exclude: z.record(
    z.record(z.array(z.lazy(() => CreateFlagSegmentExclude$outboundSchema))),
  ).optional(),
});

export function createFlagSegmentDataToJSON(
  createFlagSegmentData: CreateFlagSegmentData,
): string {
  return JSON.stringify(
    CreateFlagSegmentData$outboundSchema.parse(createFlagSegmentData),
  );
}

/** @internal */
export type CreateFlagSegmentRequestBody$Outbound = {
  slug: string;
  createdBy?: string | undefined;
  label: string;
  description?: string | undefined;
  data: CreateFlagSegmentData$Outbound;
  hint: string;
};

/** @internal */
export const CreateFlagSegmentRequestBody$outboundSchema: z.ZodType<
  CreateFlagSegmentRequestBody$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentRequestBody
> = z.object({
  slug: z.string(),
  createdBy: z.string().optional(),
  label: z.string(),
  description: z.string().optional(),
  data: z.lazy(() => CreateFlagSegmentData$outboundSchema),
  hint: z.string(),
});

export function createFlagSegmentRequestBodyToJSON(
  createFlagSegmentRequestBody: CreateFlagSegmentRequestBody,
): string {
  return JSON.stringify(
    CreateFlagSegmentRequestBody$outboundSchema.parse(
      createFlagSegmentRequestBody,
    ),
  );
}

/** @internal */
export type CreateFlagSegmentRequest$Outbound = {
  projectIdOrName: string;
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody?: CreateFlagSegmentRequestBody$Outbound | undefined;
};

/** @internal */
export const CreateFlagSegmentRequest$outboundSchema: z.ZodType<
  CreateFlagSegmentRequest$Outbound,
  z.ZodTypeDef,
  CreateFlagSegmentRequest
> = z.object({
  projectIdOrName: z.string(),
  teamId: z.string().optional(),
  slug: z.string().optional(),
  requestBody: z.lazy(() => CreateFlagSegmentRequestBody$outboundSchema)
    .optional(),
}).transform((v) => {
  return remap$(v, {
    requestBody: "RequestBody",
  });
});

export function createFlagSegmentRequestToJSON(
  createFlagSegmentRequest: CreateFlagSegmentRequest,
): string {
  return JSON.stringify(
    CreateFlagSegmentRequest$outboundSchema.parse(createFlagSegmentRequest),
  );
}

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

/** @internal */
export const CreateFlagSegmentOutcomeFeatureFlagsBase$inboundSchema: z.ZodType<
  CreateFlagSegmentOutcomeFeatureFlagsBase,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: CreateFlagSegmentOutcomeFeatureFlagsResponseType$inboundSchema,
  kind: types.string(),
  attribute: types.string(),
});

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

/** @internal */
export const CreateFlagSegmentOutcomeFeatureFlags2$inboundSchema: z.ZodType<
  CreateFlagSegmentOutcomeFeatureFlags2,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: types.literal("split"),
  base: z.lazy(() => CreateFlagSegmentOutcomeFeatureFlagsBase$inboundSchema),
  passPromille: types.number(),
});

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

/** @internal */
export const CreateFlagSegmentOutcomeFeatureFlags1$inboundSchema: z.ZodType<
  CreateFlagSegmentOutcomeFeatureFlags1,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: types.literal("all"),
});

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

/** @internal */
export const CreateFlagSegmentFeatureFlagsOutcome$inboundSchema: z.ZodType<
  CreateFlagSegmentFeatureFlagsOutcome,
  z.ZodTypeDef,
  unknown
> = z.union([
  z.lazy(() => CreateFlagSegmentOutcomeFeatureFlags1$inboundSchema),
  z.lazy(() => CreateFlagSegmentOutcomeFeatureFlags2$inboundSchema),
]);

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

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

/** @internal */
export const CreateFlagSegmentRhs4$inboundSchema: z.ZodType<
  CreateFlagSegmentRhs4,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: CreateFlagSegmentRhsFeatureFlagsResponseType$inboundSchema,
  pattern: types.string(),
  flags: types.string(),
});

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

/** @internal */
export const CreateFlagSegmentRhsFeatureFlagsType$inboundSchema:
  z.ZodNativeEnum<typeof CreateFlagSegmentRhsFeatureFlagsType> = z.nativeEnum(
    CreateFlagSegmentRhsFeatureFlagsType,
  );

/** @internal */
export const CreateFlagSegmentItemsFeatureFlags2$inboundSchema: z.ZodType<
  CreateFlagSegmentItemsFeatureFlags2,
  z.ZodTypeDef,
  unknown
> = z.object({
  label: types.optional(types.string()),
  note: types.optional(types.string()),
  value: types.string(),
});

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

/** @internal */
export const CreateFlagSegmentItemsFeatureFlags1$inboundSchema: z.ZodType<
  CreateFlagSegmentItemsFeatureFlags1,
  z.ZodTypeDef,
  unknown
> = z.object({
  label: types.optional(types.string()),
  note: types.optional(types.string()),
  value: types.number(),
});

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

/** @internal */
export const CreateFlagSegmentRhsFeatureFlagsItems$inboundSchema: z.ZodType<
  CreateFlagSegmentRhsFeatureFlagsItems,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  z.lazy(() => CreateFlagSegmentItemsFeatureFlags1$inboundSchema),
  z.lazy(() => CreateFlagSegmentItemsFeatureFlags2$inboundSchema),
]);

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

/** @internal */
export const CreateFlagSegmentRhs3$inboundSchema: z.ZodType<
  CreateFlagSegmentRhs3,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: CreateFlagSegmentRhsFeatureFlagsType$inboundSchema,
  items: z.array(
    smartUnion([
      z.lazy(() => CreateFlagSegmentItemsFeatureFlags1$inboundSchema),
      z.lazy(() => CreateFlagSegmentItemsFeatureFlags2$inboundSchema),
    ]),
  ),
});

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

/** @internal */
export const CreateFlagSegmentFeatureFlagsRhs$inboundSchema: z.ZodType<
  CreateFlagSegmentFeatureFlagsRhs,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  z.lazy(() => CreateFlagSegmentRhs4$inboundSchema),
  z.lazy(() => CreateFlagSegmentRhs3$inboundSchema),
  types.string(),
  types.number(),
  types.boolean(),
]);

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

/** @internal */
export const CreateFlagSegmentFeatureFlagsCmpOptions$inboundSchema: z.ZodType<
  CreateFlagSegmentFeatureFlagsCmpOptions,
  z.ZodTypeDef,
  unknown
> = z.object({
  ignoreCase: types.optional(types.boolean()),
});

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

/** @internal */
export const CreateFlagSegmentLhsFeatureFlags2$inboundSchema: z.ZodType<
  CreateFlagSegmentLhsFeatureFlags2,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: types.literal("entity"),
  kind: types.string(),
  attribute: types.string(),
});

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

/** @internal */
export const CreateFlagSegmentLhsFeatureFlags1$inboundSchema: z.ZodType<
  CreateFlagSegmentLhsFeatureFlags1,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: types.literal("segment"),
});

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

/** @internal */
export const CreateFlagSegmentFeatureFlagsLhs$inboundSchema: z.ZodType<
  CreateFlagSegmentFeatureFlagsLhs,
  z.ZodTypeDef,
  unknown
> = z.union([
  z.lazy(() => CreateFlagSegmentLhsFeatureFlags1$inboundSchema),
  z.lazy(() => CreateFlagSegmentLhsFeatureFlags2$inboundSchema),
]);

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

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

/** @internal */
export const CreateFlagSegmentFeatureFlagsConditions$inboundSchema: z.ZodType<
  CreateFlagSegmentFeatureFlagsConditions,
  z.ZodTypeDef,
  unknown
> = z.object({
  rhs: types.optional(
    smartUnion([
      z.lazy(() => CreateFlagSegmentRhs4$inboundSchema),
      z.lazy(() => CreateFlagSegmentRhs3$inboundSchema),
      types.string(),
      types.number(),
      types.boolean(),
    ]),
  ),
  cmpOptions: types.optional(
    z.lazy(() => CreateFlagSegmentFeatureFlagsCmpOptions$inboundSchema),
  ),
  lhs: z.union([
    z.lazy(() => CreateFlagSegmentLhsFeatureFlags1$inboundSchema),
    z.lazy(() => CreateFlagSegmentLhsFeatureFlags2$inboundSchema),
  ]),
  cmp: CreateFlagSegmentFeatureFlagsCmp$inboundSchema,
});

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

/** @internal */
export const CreateFlagSegmentFeatureFlagsRules$inboundSchema: z.ZodType<
  CreateFlagSegmentFeatureFlagsRules,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  outcome: z.union([
    z.lazy(() => CreateFlagSegmentOutcomeFeatureFlags1$inboundSchema),
    z.lazy(() => CreateFlagSegmentOutcomeFeatureFlags2$inboundSchema),
  ]),
  conditions: z.array(
    z.lazy(() => CreateFlagSegmentFeatureFlagsConditions$inboundSchema),
  ),
});

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

/** @internal */
export const CreateFlagSegmentFeatureFlagsInclude$inboundSchema: z.ZodType<
  CreateFlagSegmentFeatureFlagsInclude,
  z.ZodTypeDef,
  unknown
> = z.object({
  note: types.optional(types.string()),
  value: types.string(),
});

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

/** @internal */
export const CreateFlagSegmentFeatureFlagsExclude$inboundSchema: z.ZodType<
  CreateFlagSegmentFeatureFlagsExclude,
  z.ZodTypeDef,
  unknown
> = z.object({
  note: types.optional(types.string()),
  value: types.string(),
});

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

/** @internal */
export const CreateFlagSegmentFeatureFlagsData$inboundSchema: z.ZodType<
  CreateFlagSegmentFeatureFlagsData,
  z.ZodTypeDef,
  unknown
> = z.object({
  rules: types.optional(
    z.array(z.lazy(() => CreateFlagSegmentFeatureFlagsRules$inboundSchema)),
  ),
  include: types.optional(
    z.record(z.record(z.array(z.lazy(() =>
      CreateFlagSegmentFeatureFlagsInclude$inboundSchema
    )))),
  ),
  exclude: types.optional(
    z.record(z.record(z.array(z.lazy(() =>
      CreateFlagSegmentFeatureFlagsExclude$inboundSchema
    )))),
  ),
});

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

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

/** @internal */
export const CreateFlagSegmentResponseBody$inboundSchema: z.ZodType<
  CreateFlagSegmentResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  description: types.optional(types.string()),
  createdBy: types.optional(types.string()),
  usedByFlags: types.optional(z.array(types.string())),
  usedBySegments: types.optional(z.array(types.string())),
  data: z.lazy(() => CreateFlagSegmentFeatureFlagsData$inboundSchema),
  id: types.string(),
  label: types.string(),
  slug: types.string(),
  createdAt: types.number(),
  updatedAt: types.number(),
  projectId: types.string(),
  typeName: CreateFlagSegmentTypeName$inboundSchema,
  hint: types.string(),
});

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