/*
 * 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 { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { AuthToken, AuthToken$inboundSchema } from "./authtoken.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

export type CreateAuthTokenRequestBody = {
  name: string;
  expiresAt?: number | undefined;
  /**
   * The ID of the project to scope this token to
   */
  projectId?: string | undefined;
};

export type CreateAuthTokenRequest = {
  /**
   * 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: CreateAuthTokenRequestBody;
};

/**
 * Successful response.
 */
export type CreateAuthTokenResponseBody = {
  /**
   * Authentication token metadata.
   */
  token: AuthToken;
  /**
   * The authentication token's actual value. This token is only provided in this response, and can never be retrieved again in the future. Be sure to save it somewhere safe!
   */
  bearerToken: string;
};

/** @internal */
export type CreateAuthTokenRequestBody$Outbound = {
  name: string;
  expiresAt?: number | undefined;
  projectId?: string | undefined;
};

/** @internal */
export const CreateAuthTokenRequestBody$outboundSchema: z.ZodType<
  CreateAuthTokenRequestBody$Outbound,
  z.ZodTypeDef,
  CreateAuthTokenRequestBody
> = z.object({
  name: z.string(),
  expiresAt: z.number().optional(),
  projectId: z.string().optional(),
});

export function createAuthTokenRequestBodyToJSON(
  createAuthTokenRequestBody: CreateAuthTokenRequestBody,
): string {
  return JSON.stringify(
    CreateAuthTokenRequestBody$outboundSchema.parse(createAuthTokenRequestBody),
  );
}

/** @internal */
export type CreateAuthTokenRequest$Outbound = {
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody: CreateAuthTokenRequestBody$Outbound;
};

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

export function createAuthTokenRequestToJSON(
  createAuthTokenRequest: CreateAuthTokenRequest,
): string {
  return JSON.stringify(
    CreateAuthTokenRequest$outboundSchema.parse(createAuthTokenRequest),
  );
}

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

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