/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v3";
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";

/**
 * The role used for the invitation
 */
export const Role = {
  Billing: "BILLING",
  Contributor: "CONTRIBUTOR",
  Developer: "DEVELOPER",
  Member: "MEMBER",
  Owner: "OWNER",
  Security: "SECURITY",
  Viewer: "VIEWER",
  ViewerForPlus: "VIEWER_FOR_PLUS",
} as const;
/**
 * The role used for the invitation
 */
export type Role = ClosedEnum<typeof Role>;

/**
 * The team roles of the user
 */
export const TeamRoles = {
  Billing: "BILLING",
  Contributor: "CONTRIBUTOR",
  Developer: "DEVELOPER",
  Member: "MEMBER",
  Owner: "OWNER",
  Security: "SECURITY",
  Viewer: "VIEWER",
  ViewerForPlus: "VIEWER_FOR_PLUS",
} as const;
/**
 * The team roles of the user
 */
export type TeamRoles = ClosedEnum<typeof TeamRoles>;

/**
 * The team permissions of the user
 */
export const TeamPermissions = {
  CreateProject: "CreateProject",
  EnvVariableManager: "EnvVariableManager",
  EnvironmentManager: "EnvironmentManager",
  FullProductionDeployment: "FullProductionDeployment",
  IntegrationManager: "IntegrationManager",
  OrgAdmin: "OrgAdmin",
  OrgViewer: "OrgViewer",
  UsageViewer: "UsageViewer",
  V0Builder: "V0Builder",
  V0Chatter: "V0Chatter",
  V0Viewer: "V0Viewer",
} as const;
/**
 * The team permissions of the user
 */
export type TeamPermissions = ClosedEnum<typeof TeamPermissions>;

/**
 * The member was successfully added to the team.
 */
export type InvitedTeamMember = {
  /**
   * The ID of the invited user
   */
  uid: string;
  /**
   * The username of the invited user
   */
  username: string;
  /**
   * The email of the invited user.
   */
  email: string;
  /**
   * The role used for the invitation
   */
  role: Role;
  /**
   * The team roles of the user
   */
  teamRoles?: Array<TeamRoles> | undefined;
  /**
   * The team permissions of the user
   */
  teamPermissions?: Array<TeamPermissions> | undefined;
};

/** @internal */
export const Role$inboundSchema: z.ZodNativeEnum<typeof Role> = z.nativeEnum(
  Role,
);

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

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

/** @internal */
export const InvitedTeamMember$inboundSchema: z.ZodType<
  InvitedTeamMember,
  z.ZodTypeDef,
  unknown
> = z.object({
  uid: types.string(),
  username: types.string(),
  email: types.string(),
  role: Role$inboundSchema,
  teamRoles: types.optional(z.array(TeamRoles$inboundSchema)),
  teamPermissions: types.optional(z.array(TeamPermissions$inboundSchema)),
});

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