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

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

export type AddProjectMemberRequestBody3 = {
  /**
   * The ID of the team member that should be added to this project.
   */
  uid?: string | undefined;
  /**
   * The username of the team member that should be added to this project.
   */
  username?: string | undefined;
  /**
   * The email of the team member that should be added to this project.
   */
  email: string;
  /**
   * The project role of the member that will be added.
   */
  role: AddProjectMemberRequestBodyProjectMembersRole;
};

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

export type AddProjectMemberRequestBody2 = {
  /**
   * The ID of the team member that should be added to this project.
   */
  uid?: string | undefined;
  /**
   * The username of the team member that should be added to this project.
   */
  username: string;
  /**
   * The email of the team member that should be added to this project.
   */
  email?: string | undefined;
  /**
   * The project role of the member that will be added.
   */
  role: AddProjectMemberRequestBodyRole;
};

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

export type AddProjectMemberRequestBody1 = {
  /**
   * The ID of the team member that should be added to this project.
   */
  uid: string;
  /**
   * The username of the team member that should be added to this project.
   */
  username?: string | undefined;
  /**
   * The email of the team member that should be added to this project.
   */
  email?: string | undefined;
  /**
   * The project role of the member that will be added.
   */
  role: RequestBodyRole;
};

export type AddProjectMemberRequestBody =
  | AddProjectMemberRequestBody1
  | AddProjectMemberRequestBody2
  | AddProjectMemberRequestBody3;

export type AddProjectMemberRequest = {
  /**
   * The ID or name of the Project.
   */
  idOrName: string;
  /**
   * 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:
    | AddProjectMemberRequestBody1
    | AddProjectMemberRequestBody2
    | AddProjectMemberRequestBody3;
};

/**
 * Responds with the project ID on success.
 */
export type AddProjectMemberResponseBody = {
  id: string;
};

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

/** @internal */
export type AddProjectMemberRequestBody3$Outbound = {
  uid?: string | undefined;
  username?: string | undefined;
  email: string;
  role: string;
};

/** @internal */
export const AddProjectMemberRequestBody3$outboundSchema: z.ZodType<
  AddProjectMemberRequestBody3$Outbound,
  z.ZodTypeDef,
  AddProjectMemberRequestBody3
> = z.object({
  uid: z.string().optional(),
  username: z.string().optional(),
  email: z.string(),
  role: AddProjectMemberRequestBodyProjectMembersRole$outboundSchema,
});

export function addProjectMemberRequestBody3ToJSON(
  addProjectMemberRequestBody3: AddProjectMemberRequestBody3,
): string {
  return JSON.stringify(
    AddProjectMemberRequestBody3$outboundSchema.parse(
      addProjectMemberRequestBody3,
    ),
  );
}

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

/** @internal */
export type AddProjectMemberRequestBody2$Outbound = {
  uid?: string | undefined;
  username: string;
  email?: string | undefined;
  role: string;
};

/** @internal */
export const AddProjectMemberRequestBody2$outboundSchema: z.ZodType<
  AddProjectMemberRequestBody2$Outbound,
  z.ZodTypeDef,
  AddProjectMemberRequestBody2
> = z.object({
  uid: z.string().optional(),
  username: z.string(),
  email: z.string().optional(),
  role: AddProjectMemberRequestBodyRole$outboundSchema,
});

export function addProjectMemberRequestBody2ToJSON(
  addProjectMemberRequestBody2: AddProjectMemberRequestBody2,
): string {
  return JSON.stringify(
    AddProjectMemberRequestBody2$outboundSchema.parse(
      addProjectMemberRequestBody2,
    ),
  );
}

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

/** @internal */
export type AddProjectMemberRequestBody1$Outbound = {
  uid: string;
  username?: string | undefined;
  email?: string | undefined;
  role: string;
};

/** @internal */
export const AddProjectMemberRequestBody1$outboundSchema: z.ZodType<
  AddProjectMemberRequestBody1$Outbound,
  z.ZodTypeDef,
  AddProjectMemberRequestBody1
> = z.object({
  uid: z.string(),
  username: z.string().optional(),
  email: z.string().optional(),
  role: RequestBodyRole$outboundSchema,
});

export function addProjectMemberRequestBody1ToJSON(
  addProjectMemberRequestBody1: AddProjectMemberRequestBody1,
): string {
  return JSON.stringify(
    AddProjectMemberRequestBody1$outboundSchema.parse(
      addProjectMemberRequestBody1,
    ),
  );
}

/** @internal */
export type AddProjectMemberRequestBody$Outbound =
  | AddProjectMemberRequestBody1$Outbound
  | AddProjectMemberRequestBody2$Outbound
  | AddProjectMemberRequestBody3$Outbound;

/** @internal */
export const AddProjectMemberRequestBody$outboundSchema: z.ZodType<
  AddProjectMemberRequestBody$Outbound,
  z.ZodTypeDef,
  AddProjectMemberRequestBody
> = smartUnion([
  z.lazy(() => AddProjectMemberRequestBody1$outboundSchema),
  z.lazy(() => AddProjectMemberRequestBody2$outboundSchema),
  z.lazy(() => AddProjectMemberRequestBody3$outboundSchema),
]);

export function addProjectMemberRequestBodyToJSON(
  addProjectMemberRequestBody: AddProjectMemberRequestBody,
): string {
  return JSON.stringify(
    AddProjectMemberRequestBody$outboundSchema.parse(
      addProjectMemberRequestBody,
    ),
  );
}

/** @internal */
export type AddProjectMemberRequest$Outbound = {
  idOrName: string;
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody:
    | AddProjectMemberRequestBody1$Outbound
    | AddProjectMemberRequestBody2$Outbound
    | AddProjectMemberRequestBody3$Outbound;
};

/** @internal */
export const AddProjectMemberRequest$outboundSchema: z.ZodType<
  AddProjectMemberRequest$Outbound,
  z.ZodTypeDef,
  AddProjectMemberRequest
> = z.object({
  idOrName: z.string(),
  teamId: z.string().optional(),
  slug: z.string().optional(),
  requestBody: smartUnion([
    z.lazy(() => AddProjectMemberRequestBody1$outboundSchema),
    z.lazy(() => AddProjectMemberRequestBody2$outboundSchema),
    z.lazy(() => AddProjectMemberRequestBody3$outboundSchema),
  ]),
}).transform((v) => {
  return remap$(v, {
    requestBody: "RequestBody",
  });
});

export function addProjectMemberRequestToJSON(
  addProjectMemberRequest: AddProjectMemberRequest,
): string {
  return JSON.stringify(
    AddProjectMemberRequest$outboundSchema.parse(addProjectMemberRequest),
  );
}

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

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