/*
 * 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";

/**
 * The default app for the new microfrontend group
 */
export type DefaultApp = {
  /**
   * The id of the project that will be used as the default app for the new microfrontend group
   */
  projectId: string;
  /**
   * The default route for the default app of the new microfrontend group
   */
  defaultRoute?: string | undefined;
};

export type OtherApplications = {
  /**
   * The id of the project that will be used in the new microfrontend group
   */
  projectId: string;
  /**
   * The default route for the application in the new microfrontend group
   */
  defaultRoute?: string | undefined;
};

export type CreateMicrofrontendsGroupWithApplicationsRequestBody = {
  /**
   * The name of the microfrontends group that will be used to identify the group
   */
  groupName: string;
  /**
   * The default app for the new microfrontend group
   */
  defaultApp: DefaultApp;
  /**
   * The list of other applications that will be used in the new microfrontend group
   */
  otherApplications: Array<OtherApplications>;
};

export type CreateMicrofrontendsGroupWithApplicationsRequest = {
  /**
   * 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?:
    | CreateMicrofrontendsGroupWithApplicationsRequestBody
    | undefined;
};

export type NewMicrofrontendsGroup = {
  id: string;
  slug: string;
  name: string;
  fallbackEnvironment: string;
  enablePolyrepoBranchRouting: boolean;
  createdAt: number;
  updatedAt: number;
};

export type CreateMicrofrontendsGroupWithApplicationsResponseBody = {
  newMicrofrontendsGroup: NewMicrofrontendsGroup;
};

/** @internal */
export type DefaultApp$Outbound = {
  projectId: string;
  defaultRoute?: string | undefined;
};

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

export function defaultAppToJSON(defaultApp: DefaultApp): string {
  return JSON.stringify(DefaultApp$outboundSchema.parse(defaultApp));
}

/** @internal */
export type OtherApplications$Outbound = {
  projectId: string;
  defaultRoute?: string | undefined;
};

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

export function otherApplicationsToJSON(
  otherApplications: OtherApplications,
): string {
  return JSON.stringify(
    OtherApplications$outboundSchema.parse(otherApplications),
  );
}

/** @internal */
export type CreateMicrofrontendsGroupWithApplicationsRequestBody$Outbound = {
  groupName: string;
  defaultApp: DefaultApp$Outbound;
  otherApplications: Array<OtherApplications$Outbound>;
};

/** @internal */
export const CreateMicrofrontendsGroupWithApplicationsRequestBody$outboundSchema:
  z.ZodType<
    CreateMicrofrontendsGroupWithApplicationsRequestBody$Outbound,
    z.ZodTypeDef,
    CreateMicrofrontendsGroupWithApplicationsRequestBody
  > = z.object({
    groupName: z.string(),
    defaultApp: z.lazy(() => DefaultApp$outboundSchema),
    otherApplications: z.array(z.lazy(() => OtherApplications$outboundSchema)),
  });

export function createMicrofrontendsGroupWithApplicationsRequestBodyToJSON(
  createMicrofrontendsGroupWithApplicationsRequestBody:
    CreateMicrofrontendsGroupWithApplicationsRequestBody,
): string {
  return JSON.stringify(
    CreateMicrofrontendsGroupWithApplicationsRequestBody$outboundSchema.parse(
      createMicrofrontendsGroupWithApplicationsRequestBody,
    ),
  );
}

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

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

export function createMicrofrontendsGroupWithApplicationsRequestToJSON(
  createMicrofrontendsGroupWithApplicationsRequest:
    CreateMicrofrontendsGroupWithApplicationsRequest,
): string {
  return JSON.stringify(
    CreateMicrofrontendsGroupWithApplicationsRequest$outboundSchema.parse(
      createMicrofrontendsGroupWithApplicationsRequest,
    ),
  );
}

/** @internal */
export const NewMicrofrontendsGroup$inboundSchema: z.ZodType<
  NewMicrofrontendsGroup,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: types.string(),
  slug: types.string(),
  name: types.string(),
  fallbackEnvironment: types.string(),
  enablePolyrepoBranchRouting: types.boolean(),
  createdAt: types.number(),
  updatedAt: types.number(),
});

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

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

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