/*
 * 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 PatchFeatureFlagRequest = {
  /**
   * The project key
   */
  projectKey: string;
  /**
   * The feature flag key. The key identifies the flag in your code.
   */
  featureFlagKey: string;
  /**
   * If true, the patch will be applied even if it causes a pending scheduled change or approval request to fail.
   */
  ignoreConflicts?: boolean | undefined;
  /**
   * If true, the patch will be validated but not persisted. Returns a preview of the flag after the patch is applied.
   */
  dryRun?: boolean | undefined;
  patchWithComment: components.PatchWithComment;
};

/** @internal */
export const PatchFeatureFlagRequest$inboundSchema: z.ZodType<
  PatchFeatureFlagRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  projectKey: z.string(),
  featureFlagKey: z.string(),
  ignoreConflicts: z.boolean().optional(),
  dryRun: z.boolean().optional(),
  PatchWithComment: components.PatchWithComment$inboundSchema,
}).transform((v) => {
  return remap$(v, {
    "PatchWithComment": "patchWithComment",
  });
});
/** @internal */
export type PatchFeatureFlagRequest$Outbound = {
  projectKey: string;
  featureFlagKey: string;
  ignoreConflicts?: boolean | undefined;
  dryRun?: boolean | undefined;
  PatchWithComment: components.PatchWithComment$Outbound;
};

/** @internal */
export const PatchFeatureFlagRequest$outboundSchema: z.ZodType<
  PatchFeatureFlagRequest$Outbound,
  z.ZodTypeDef,
  PatchFeatureFlagRequest
> = z.object({
  projectKey: z.string(),
  featureFlagKey: z.string(),
  ignoreConflicts: z.boolean().optional(),
  dryRun: z.boolean().optional(),
  patchWithComment: components.PatchWithComment$outboundSchema,
}).transform((v) => {
  return remap$(v, {
    patchWithComment: "PatchWithComment",
  });
});

export function patchFeatureFlagRequestToJSON(
  patchFeatureFlagRequest: PatchFeatureFlagRequest,
): string {
  return JSON.stringify(
    PatchFeatureFlagRequest$outboundSchema.parse(patchFeatureFlagRequest),
  );
}
export function patchFeatureFlagRequestFromJSON(
  jsonString: string,
): SafeParseResult<PatchFeatureFlagRequest, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => PatchFeatureFlagRequest$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'PatchFeatureFlagRequest' from JSON`,
  );
}
