/*
 * 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";

export type GetSharedEnvVarRequest = {
  /**
   * The unique ID for the Shared Environment Variable to get the decrypted value.
   */
  id: 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;
};

/**
 * The type of this cosmos doc instance, if blank, assume secret.
 */
export const GetSharedEnvVarType = {
  Encrypted: "encrypted",
  Plain: "plain",
  Sensitive: "sensitive",
  System: "system",
} as const;
/**
 * The type of this cosmos doc instance, if blank, assume secret.
 */
export type GetSharedEnvVarType = ClosedEnum<typeof GetSharedEnvVarType>;

/**
 * environments this env variable targets
 */
export const GetSharedEnvVarTarget = {
  Development: "development",
  Preview: "preview",
  Production: "production",
} as const;
/**
 * environments this env variable targets
 */
export type GetSharedEnvVarTarget = ClosedEnum<typeof GetSharedEnvVarTarget>;

export type GetSharedEnvVarResponseBody = {
  /**
   * The date when the Shared Env Var was created.
   */
  created?: Date | undefined;
  /**
   * The name of the Shared Env Var.
   */
  key?: string | undefined;
  /**
   * The unique identifier of the owner (team) the Shared Env Var was created for.
   */
  ownerId?: string | null | undefined;
  /**
   * The unique identifier of the Shared Env Var.
   */
  id?: string | undefined;
  /**
   * The unique identifier of the user who created the Shared Env Var.
   */
  createdBy?: string | null | undefined;
  /**
   * The unique identifier of the user who deleted the Shared Env Var.
   */
  deletedBy?: string | null | undefined;
  /**
   * The unique identifier of the user who last updated the Shared Env Var.
   */
  updatedBy?: string | null | undefined;
  /**
   * Timestamp for when the Shared Env Var was created.
   */
  createdAt?: number | undefined;
  /**
   * Timestamp for when the Shared Env Var was (soft) deleted.
   */
  deletedAt?: number | undefined;
  /**
   * Timestamp for when the Shared Env Var was last updated.
   */
  updatedAt?: number | undefined;
  /**
   * The value of the Shared Env Var.
   */
  value?: string | undefined;
  /**
   * The unique identifiers of the projects which the Shared Env Var is linked to.
   */
  projectId?: Array<string> | undefined;
  /**
   * The type of this cosmos doc instance, if blank, assume secret.
   */
  type?: GetSharedEnvVarType | undefined;
  /**
   * environments this env variable targets
   */
  target?: Array<GetSharedEnvVarTarget> | undefined;
  /**
   * whether or not this env varible applies to custom environments
   */
  applyToAllCustomEnvironments?: boolean | undefined;
  /**
   * The custom environment IDs that this Shared Env Var is scoped to.
   */
  customEnvironmentIds?: Array<string> | undefined;
  /**
   * whether or not this env variable is decrypted
   */
  decrypted?: boolean | undefined;
  /**
   * A user provided comment that describes what this Shared Env Var is for.
   */
  comment?: string | undefined;
  /**
   * The last editor full name or username.
   */
  lastEditedByDisplayName?: string | undefined;
};

/** @internal */
export type GetSharedEnvVarRequest$Outbound = {
  id: string;
  teamId?: string | undefined;
  slug?: string | undefined;
};

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

export function getSharedEnvVarRequestToJSON(
  getSharedEnvVarRequest: GetSharedEnvVarRequest,
): string {
  return JSON.stringify(
    GetSharedEnvVarRequest$outboundSchema.parse(getSharedEnvVarRequest),
  );
}

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

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

/** @internal */
export const GetSharedEnvVarResponseBody$inboundSchema: z.ZodType<
  GetSharedEnvVarResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  created: types.optional(types.date()),
  key: types.optional(types.string()),
  ownerId: z.nullable(types.string()).optional(),
  id: types.optional(types.string()),
  createdBy: z.nullable(types.string()).optional(),
  deletedBy: z.nullable(types.string()).optional(),
  updatedBy: z.nullable(types.string()).optional(),
  createdAt: types.optional(types.number()),
  deletedAt: types.optional(types.number()),
  updatedAt: types.optional(types.number()),
  value: types.optional(types.string()),
  projectId: types.optional(z.array(types.string())),
  type: types.optional(GetSharedEnvVarType$inboundSchema),
  target: types.optional(z.array(GetSharedEnvVarTarget$inboundSchema)),
  applyToAllCustomEnvironments: types.optional(types.boolean()),
  customEnvironmentIds: types.optional(z.array(types.string())),
  decrypted: types.optional(types.boolean()),
  comment: types.optional(types.string()),
  lastEditedByDisplayName: types.optional(types.string()),
});

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