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

import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type FlagInput = {
  /**
   * The ID of the variation or rollout of the flag to use. Use "fallthrough" for the default targeting behavior when the flag is on.
   */
  ruleId: string;
  /**
   * The flag version
   */
  flagConfigVersion: number;
  /**
   * The ID of the variation to route traffic not part of the experiment analysis to. Defaults to variation ID of baseline treatment, if set.
   */
  notInExperimentVariationId?: string | undefined;
};

/** @internal */
export const FlagInput$inboundSchema: z.ZodType<
  FlagInput,
  z.ZodTypeDef,
  unknown
> = z.object({
  ruleId: z.string(),
  flagConfigVersion: z.number().int(),
  notInExperimentVariationId: z.string().optional(),
});
/** @internal */
export type FlagInput$Outbound = {
  ruleId: string;
  flagConfigVersion: number;
  notInExperimentVariationId?: string | undefined;
};

/** @internal */
export const FlagInput$outboundSchema: z.ZodType<
  FlagInput$Outbound,
  z.ZodTypeDef,
  FlagInput
> = z.object({
  ruleId: z.string(),
  flagConfigVersion: z.number().int(),
  notInExperimentVariationId: z.string().optional(),
});

export function flagInputToJSON(flagInput: FlagInput): string {
  return JSON.stringify(FlagInput$outboundSchema.parse(flagInput));
}
export function flagInputFromJSON(
  jsonString: string,
): SafeParseResult<FlagInput, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => FlagInput$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'FlagInput' from JSON`,
  );
}
