/*
 * 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 types from "../types/primitives.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

export type UpdateMicrofrontendsGroupRequestBody = {
  /**
   * The new name for the existing microfrontends group.
   */
  name?: string | undefined;
  /**
   * The new fallback environment for the microfrontends group. Must be "SAME_ENV", "PRODUCTION", or a valid custom environment slug from the default app.
   */
  fallbackEnvironment?: string | undefined;
};

export type UpdateMicrofrontendsGroupRequest = {
  groupId: string;
  /**
   * 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;
  requestBody?: UpdateMicrofrontendsGroupRequestBody | undefined;
};

export type UpdatedMicrofrontendsGroup = {
  name?: string | undefined;
  slug?: string | undefined;
  id: string;
  fallbackEnvironment?: string | undefined;
};

export type UpdateMicrofrontendsGroupResponseBody = {
  updatedMicrofrontendsGroup: UpdatedMicrofrontendsGroup;
};

/** @internal */
export type UpdateMicrofrontendsGroupRequestBody$Outbound = {
  name?: string | undefined;
  fallbackEnvironment?: string | undefined;
};

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

export function updateMicrofrontendsGroupRequestBodyToJSON(
  updateMicrofrontendsGroupRequestBody: UpdateMicrofrontendsGroupRequestBody,
): string {
  return JSON.stringify(
    UpdateMicrofrontendsGroupRequestBody$outboundSchema.parse(
      updateMicrofrontendsGroupRequestBody,
    ),
  );
}

/** @internal */
export type UpdateMicrofrontendsGroupRequest$Outbound = {
  groupId: string;
  teamId: string;
  slug?: string | undefined;
  RequestBody?: UpdateMicrofrontendsGroupRequestBody$Outbound | undefined;
};

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

export function updateMicrofrontendsGroupRequestToJSON(
  updateMicrofrontendsGroupRequest: UpdateMicrofrontendsGroupRequest,
): string {
  return JSON.stringify(
    UpdateMicrofrontendsGroupRequest$outboundSchema.parse(
      updateMicrofrontendsGroupRequest,
    ),
  );
}

/** @internal */
export const UpdatedMicrofrontendsGroup$inboundSchema: z.ZodType<
  UpdatedMicrofrontendsGroup,
  z.ZodTypeDef,
  unknown
> = z.object({
  name: types.optional(types.string()),
  slug: types.optional(types.string()),
  id: types.string(),
  fallbackEnvironment: types.optional(types.string()),
});

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

/** @internal */
export const UpdateMicrofrontendsGroupResponseBody$inboundSchema: z.ZodType<
  UpdateMicrofrontendsGroupResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  updatedMicrofrontendsGroup: z.lazy(() =>
    UpdatedMicrofrontendsGroup$inboundSchema
  ),
});

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