/*
 * 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 { Result as SafeParseResult } from "../../types/fp.js";
import * as components from "../components/index.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type PostFeatureFlagRequest = {
  /**
   * The project key
   */
  projectKey: string;
  /**
   * The key of the feature flag to be cloned. The key identifies the flag in your code. For example, setting `clone=flagKey` copies the full targeting configuration for all environments, including `on/off` state, from the original flag to the new flag.
   */
  clone?: string | undefined;
  featureFlagBody: components.FeatureFlagBody;
};

/** @internal */
export const PostFeatureFlagRequest$inboundSchema: z.ZodType<
  PostFeatureFlagRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  projectKey: z.string(),
  clone: z.string().optional(),
  FeatureFlagBody: components.FeatureFlagBody$inboundSchema,
}).transform((v) => {
  return remap$(v, {
    "FeatureFlagBody": "featureFlagBody",
  });
});
/** @internal */
export type PostFeatureFlagRequest$Outbound = {
  projectKey: string;
  clone?: string | undefined;
  FeatureFlagBody: components.FeatureFlagBody$Outbound;
};

/** @internal */
export const PostFeatureFlagRequest$outboundSchema: z.ZodType<
  PostFeatureFlagRequest$Outbound,
  z.ZodTypeDef,
  PostFeatureFlagRequest
> = z.object({
  projectKey: z.string(),
  clone: z.string().optional(),
  featureFlagBody: components.FeatureFlagBody$outboundSchema,
}).transform((v) => {
  return remap$(v, {
    featureFlagBody: "FeatureFlagBody",
  });
});

export function postFeatureFlagRequestToJSON(
  postFeatureFlagRequest: PostFeatureFlagRequest,
): string {
  return JSON.stringify(
    PostFeatureFlagRequest$outboundSchema.parse(postFeatureFlagRequest),
  );
}
export function postFeatureFlagRequestFromJSON(
  jsonString: string,
): SafeParseResult<PostFeatureFlagRequest, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => PostFeatureFlagRequest$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'PostFeatureFlagRequest' from JSON`,
  );
}
