/*
 * 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 GetTeamAccessRequestRequest = {
  userId: string;
  teamId: string;
};

export const GetTeamAccessRequestOrigin = {
  AccountUpdate: "account-update",
  Bitbucket: "bitbucket",
  Dsync: "dsync",
  Feedback: "feedback",
  Github: "github",
  Gitlab: "gitlab",
  Import: "import",
  Link: "link",
  Mail: "mail",
  NsnbAutoApprove: "nsnb-auto-approve",
  NsnbHobbyUpgrade: "nsnb-hobby-upgrade",
  NsnbInvite: "nsnb-invite",
  NsnbRedeploy: "nsnb-redeploy",
  NsnbRedeployAttributionCard: "nsnb-redeploy-attribution-card",
  NsnbRequestAccess: "nsnb-request-access",
  NsnbViewerUpgrade: "nsnb-viewer-upgrade",
  OrganizationTeams: "organization-teams",
  Saml: "saml",
  Teams: "teams",
} as const;
export type GetTeamAccessRequestOrigin = ClosedEnum<
  typeof GetTeamAccessRequestOrigin
>;

export type GetTeamAccessRequestGitUserId = string | number;

/**
 * A map that describes the origin from where the user joined.
 */
export type GetTeamAccessRequestJoinedFrom = {
  origin: GetTeamAccessRequestOrigin;
  commitId?: string | undefined;
  repoId?: string | undefined;
  repoPath?: string | undefined;
  gitUserId?: string | number | undefined;
  gitUserLogin?: string | undefined;
  ssoUserId?: string | undefined;
  ssoConnectedAt?: number | undefined;
  idpUserId?: string | undefined;
  dsyncUserId?: string | undefined;
  dsyncConnectedAt?: number | undefined;
};

/**
 * Map of the connected GitHub account.
 */
export type GetTeamAccessRequestGithub = {
  login?: string | undefined;
};

/**
 * Map of the connected GitLab account.
 */
export type GetTeamAccessRequestGitlab = {
  login?: string | undefined;
};

/**
 * Map of the connected Bitbucket account.
 */
export type GetTeamAccessRequestBitbucket = {
  login?: string | undefined;
};

/**
 * Successfully
 */
export type GetTeamAccessRequestResponseBody = {
  /**
   * The slug of the team.
   */
  teamSlug: string;
  /**
   * The name of the team.
   */
  teamName: string;
  /**
   * Current status of the membership. Will be `true` if confirmed, if pending it'll be `false`.
   */
  confirmed: boolean;
  /**
   * A map that describes the origin from where the user joined.
   */
  joinedFrom: GetTeamAccessRequestJoinedFrom;
  /**
   * Timestamp in milliseconds when the user requested access to the team.
   */
  accessRequestedAt: number;
  /**
   * Map of the connected GitHub account.
   */
  github: GetTeamAccessRequestGithub | null;
  /**
   * Map of the connected GitLab account.
   */
  gitlab: GetTeamAccessRequestGitlab | null;
  /**
   * Map of the connected Bitbucket account.
   */
  bitbucket: GetTeamAccessRequestBitbucket | null;
};

/** @internal */
export type GetTeamAccessRequestRequest$Outbound = {
  userId: string;
  teamId: string;
};

/** @internal */
export const GetTeamAccessRequestRequest$outboundSchema: z.ZodType<
  GetTeamAccessRequestRequest$Outbound,
  z.ZodTypeDef,
  GetTeamAccessRequestRequest
> = z.object({
  userId: z.string(),
  teamId: z.string(),
});

export function getTeamAccessRequestRequestToJSON(
  getTeamAccessRequestRequest: GetTeamAccessRequestRequest,
): string {
  return JSON.stringify(
    GetTeamAccessRequestRequest$outboundSchema.parse(
      getTeamAccessRequestRequest,
    ),
  );
}

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

/** @internal */
export const GetTeamAccessRequestGitUserId$inboundSchema: z.ZodType<
  GetTeamAccessRequestGitUserId,
  z.ZodTypeDef,
  unknown
> = smartUnion([types.string(), types.number()]);

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

/** @internal */
export const GetTeamAccessRequestJoinedFrom$inboundSchema: z.ZodType<
  GetTeamAccessRequestJoinedFrom,
  z.ZodTypeDef,
  unknown
> = z.object({
  origin: GetTeamAccessRequestOrigin$inboundSchema,
  commitId: types.optional(types.string()),
  repoId: types.optional(types.string()),
  repoPath: types.optional(types.string()),
  gitUserId: types.optional(smartUnion([types.string(), types.number()])),
  gitUserLogin: types.optional(types.string()),
  ssoUserId: types.optional(types.string()),
  ssoConnectedAt: types.optional(types.number()),
  idpUserId: types.optional(types.string()),
  dsyncUserId: types.optional(types.string()),
  dsyncConnectedAt: types.optional(types.number()),
});

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

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

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

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

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

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

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

/** @internal */
export const GetTeamAccessRequestResponseBody$inboundSchema: z.ZodType<
  GetTeamAccessRequestResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  teamSlug: types.string(),
  teamName: types.string(),
  confirmed: types.boolean(),
  joinedFrom: z.lazy(() => GetTeamAccessRequestJoinedFrom$inboundSchema),
  accessRequestedAt: types.number(),
  github: types.nullable(
    z.lazy(() => GetTeamAccessRequestGithub$inboundSchema),
  ),
  gitlab: types.nullable(
    z.lazy(() => GetTeamAccessRequestGitlab$inboundSchema),
  ),
  bitbucket: types.nullable(
    z.lazy(() => GetTeamAccessRequestBitbucket$inboundSchema),
  ),
});

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