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

export const UpdateTeamMemberTeamPermissions = {
  IntegrationManager: "IntegrationManager",
  CreateProject: "CreateProject",
  FullProductionDeployment: "FullProductionDeployment",
  UsageViewer: "UsageViewer",
  EnvVariableManager: "EnvVariableManager",
  EnvironmentManager: "EnvironmentManager",
  OrgAdmin: "OrgAdmin",
  OrgViewer: "OrgViewer",
  V0Builder: "V0Builder",
  V0Chatter: "V0Chatter",
  V0Viewer: "V0Viewer",
} as const;
export type UpdateTeamMemberTeamPermissions = ClosedEnum<
  typeof UpdateTeamMemberTeamPermissions
>;

/**
 * The project role of the member that will be added. \"null\" will remove this project level role.
 */
export const UpdateTeamMemberRole = {
  Admin: "ADMIN",
  ProjectViewer: "PROJECT_VIEWER",
  ProjectDeveloper: "PROJECT_DEVELOPER",
} as const;
/**
 * The project role of the member that will be added. \"null\" will remove this project level role.
 */
export type UpdateTeamMemberRole = ClosedEnum<typeof UpdateTeamMemberRole>;

export type UpdateTeamMemberProjects = {
  /**
   * The ID of the project.
   */
  projectId: string;
  /**
   * The project role of the member that will be added. \"null\" will remove this project level role.
   */
  role: UpdateTeamMemberRole | null;
};

export type UpdateTeamMemberJoinedFrom = {
  ssoUserId?: any | null | undefined;
};

export type UpdateTeamMemberRequestBody = {
  /**
   * Accept a user who requested access to the team.
   */
  confirmed?: true | undefined;
  /**
   * The role in the team of the member.
   */
  role?: string | undefined;
  /**
   * The team permissions to set for the member. Permissions must be compatible with the team roles assigned to the member.
   */
  teamPermissions?: Array<UpdateTeamMemberTeamPermissions> | undefined;
  projects?: Array<UpdateTeamMemberProjects> | undefined;
  joinedFrom?: UpdateTeamMemberJoinedFrom | undefined;
};

export type UpdateTeamMemberRequest = {
  /**
   * The ID of the member.
   */
  uid: string;
  teamId: string;
  requestBody: UpdateTeamMemberRequestBody;
};

/**
 * Successfully updated the membership.
 */
export type UpdateTeamMemberResponseBody = {
  /**
   * ID of the team.
   */
  id: string;
};

/** @internal */
export const UpdateTeamMemberTeamPermissions$outboundSchema: z.ZodNativeEnum<
  typeof UpdateTeamMemberTeamPermissions
> = z.nativeEnum(UpdateTeamMemberTeamPermissions);

/** @internal */
export const UpdateTeamMemberRole$outboundSchema: z.ZodNativeEnum<
  typeof UpdateTeamMemberRole
> = z.nativeEnum(UpdateTeamMemberRole);

/** @internal */
export type UpdateTeamMemberProjects$Outbound = {
  projectId: string;
  role: string | null;
};

/** @internal */
export const UpdateTeamMemberProjects$outboundSchema: z.ZodType<
  UpdateTeamMemberProjects$Outbound,
  z.ZodTypeDef,
  UpdateTeamMemberProjects
> = z.object({
  projectId: z.string(),
  role: z.nullable(UpdateTeamMemberRole$outboundSchema),
});

export function updateTeamMemberProjectsToJSON(
  updateTeamMemberProjects: UpdateTeamMemberProjects,
): string {
  return JSON.stringify(
    UpdateTeamMemberProjects$outboundSchema.parse(updateTeamMemberProjects),
  );
}

/** @internal */
export type UpdateTeamMemberJoinedFrom$Outbound = {
  ssoUserId?: any | null | undefined;
};

/** @internal */
export const UpdateTeamMemberJoinedFrom$outboundSchema: z.ZodType<
  UpdateTeamMemberJoinedFrom$Outbound,
  z.ZodTypeDef,
  UpdateTeamMemberJoinedFrom
> = z.object({
  ssoUserId: z.nullable(z.any()).optional(),
});

export function updateTeamMemberJoinedFromToJSON(
  updateTeamMemberJoinedFrom: UpdateTeamMemberJoinedFrom,
): string {
  return JSON.stringify(
    UpdateTeamMemberJoinedFrom$outboundSchema.parse(updateTeamMemberJoinedFrom),
  );
}

/** @internal */
export type UpdateTeamMemberRequestBody$Outbound = {
  confirmed?: true | undefined;
  role: string;
  teamPermissions?: Array<string> | undefined;
  projects?: Array<UpdateTeamMemberProjects$Outbound> | undefined;
  joinedFrom?: UpdateTeamMemberJoinedFrom$Outbound | undefined;
};

/** @internal */
export const UpdateTeamMemberRequestBody$outboundSchema: z.ZodType<
  UpdateTeamMemberRequestBody$Outbound,
  z.ZodTypeDef,
  UpdateTeamMemberRequestBody
> = z.object({
  confirmed: z.literal(true).optional(),
  role: z.string().default("MEMBER"),
  teamPermissions: z.array(UpdateTeamMemberTeamPermissions$outboundSchema)
    .optional(),
  projects: z.array(z.lazy(() => UpdateTeamMemberProjects$outboundSchema))
    .optional(),
  joinedFrom: z.lazy(() => UpdateTeamMemberJoinedFrom$outboundSchema)
    .optional(),
});

export function updateTeamMemberRequestBodyToJSON(
  updateTeamMemberRequestBody: UpdateTeamMemberRequestBody,
): string {
  return JSON.stringify(
    UpdateTeamMemberRequestBody$outboundSchema.parse(
      updateTeamMemberRequestBody,
    ),
  );
}

/** @internal */
export type UpdateTeamMemberRequest$Outbound = {
  uid: string;
  teamId: string;
  RequestBody: UpdateTeamMemberRequestBody$Outbound;
};

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

export function updateTeamMemberRequestToJSON(
  updateTeamMemberRequest: UpdateTeamMemberRequest,
): string {
  return JSON.stringify(
    UpdateTeamMemberRequest$outboundSchema.parse(updateTeamMemberRequest),
  );
}

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

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