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

export type GetProjectMembersRequest = {
  /**
   * The ID or name of the Project.
   */
  idOrName: string;
  /**
   * Limit how many project members should be returned
   */
  limit?: number | undefined;
  /**
   * Timestamp in milliseconds to only include members added since then.
   */
  since?: number | undefined;
  /**
   * Timestamp in milliseconds to only include members added until then.
   */
  until?: number | undefined;
  /**
   * Search project members by their name, username, and email.
   */
  search?: string | undefined;
  /**
   * 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;
};

/**
 * Role of this user in the project.
 */
export const ResponseBodyRole = {
  Admin: "ADMIN",
  ProjectDeveloper: "PROJECT_DEVELOPER",
  ProjectGuest: "PROJECT_GUEST",
  ProjectViewer: "PROJECT_VIEWER",
} as const;
/**
 * Role of this user in the project.
 */
export type ResponseBodyRole = ClosedEnum<typeof ResponseBodyRole>;

/**
 * Role of this user in the project.
 */
export const ComputedProjectRole = {
  Admin: "ADMIN",
  ProjectDeveloper: "PROJECT_DEVELOPER",
  ProjectGuest: "PROJECT_GUEST",
  ProjectViewer: "PROJECT_VIEWER",
} as const;
/**
 * Role of this user in the project.
 */
export type ComputedProjectRole = ClosedEnum<typeof ComputedProjectRole>;

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

export type ResponseBodyMembers = {
  /**
   * ID of the file for the Avatar of this member.
   */
  avatar?: string | undefined;
  /**
   * The email of this member.
   */
  email: string;
  /**
   * Role of this user in the project.
   */
  role: ResponseBodyRole;
  /**
   * Role of this user in the project.
   */
  computedProjectRole: ComputedProjectRole;
  /**
   * The ID of this user.
   */
  uid: string;
  /**
   * The unique username of this user.
   */
  username: string;
  /**
   * The name of this user.
   */
  name?: string | undefined;
  /**
   * Timestamp in milliseconds when this member was added.
   */
  createdAt: number;
  /**
   * The role of this user in the team.
   */
  teamRole: ResponseBodyTeamRole;
};

export type GetProjectMembersResponseBodyPagination = {
  hasNext: boolean;
  /**
   * Amount of items in the current page.
   */
  count: number;
  /**
   * Timestamp that must be used to request the next page.
   */
  next: number | null;
  /**
   * Timestamp that must be used to request the previous page.
   */
  prev: number | null;
};

/**
 * Paginated list of members for the project.
 */
export type GetProjectMembersResponseBody2 = {
  members: Array<ResponseBodyMembers>;
  pagination: GetProjectMembersResponseBodyPagination;
};

export type GetProjectMembersResponseBody1 = {};

/**
 * Paginated list of members for the project.
 */
export type GetProjectMembersResponseBody =
  | GetProjectMembersResponseBody2
  | GetProjectMembersResponseBody1;

/** @internal */
export type GetProjectMembersRequest$Outbound = {
  idOrName: string;
  limit?: number | undefined;
  since?: number | undefined;
  until?: number | undefined;
  search?: string | undefined;
  teamId?: string | undefined;
  slug?: string | undefined;
};

/** @internal */
export const GetProjectMembersRequest$outboundSchema: z.ZodType<
  GetProjectMembersRequest$Outbound,
  z.ZodTypeDef,
  GetProjectMembersRequest
> = z.object({
  idOrName: z.string(),
  limit: z.number().int().optional(),
  since: z.number().int().optional(),
  until: z.number().int().optional(),
  search: z.string().optional(),
  teamId: z.string().optional(),
  slug: z.string().optional(),
});

export function getProjectMembersRequestToJSON(
  getProjectMembersRequest: GetProjectMembersRequest,
): string {
  return JSON.stringify(
    GetProjectMembersRequest$outboundSchema.parse(getProjectMembersRequest),
  );
}

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

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

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

/** @internal */
export const ResponseBodyMembers$inboundSchema: z.ZodType<
  ResponseBodyMembers,
  z.ZodTypeDef,
  unknown
> = z.object({
  avatar: types.optional(types.string()),
  email: types.string(),
  role: ResponseBodyRole$inboundSchema,
  computedProjectRole: ComputedProjectRole$inboundSchema,
  uid: types.string(),
  username: types.string(),
  name: types.optional(types.string()),
  createdAt: types.number(),
  teamRole: ResponseBodyTeamRole$inboundSchema,
});

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

/** @internal */
export const GetProjectMembersResponseBodyPagination$inboundSchema: z.ZodType<
  GetProjectMembersResponseBodyPagination,
  z.ZodTypeDef,
  unknown
> = z.object({
  hasNext: types.boolean(),
  count: types.number(),
  next: types.nullable(types.number()),
  prev: types.nullable(types.number()),
});

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

/** @internal */
export const GetProjectMembersResponseBody2$inboundSchema: z.ZodType<
  GetProjectMembersResponseBody2,
  z.ZodTypeDef,
  unknown
> = z.object({
  members: z.array(z.lazy(() => ResponseBodyMembers$inboundSchema)),
  pagination: z.lazy(() =>
    GetProjectMembersResponseBodyPagination$inboundSchema
  ),
});

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

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

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

/** @internal */
export const GetProjectMembersResponseBody$inboundSchema: z.ZodType<
  GetProjectMembersResponseBody,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  z.lazy(() => GetProjectMembersResponseBody2$inboundSchema),
  z.lazy(() => GetProjectMembersResponseBody1$inboundSchema),
]);

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