/*
 * 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 { Pagination, Pagination$inboundSchema } from "./pagination.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

export type ListSharedEnvVariableRequest = {
  search?: string | undefined;
  /**
   * Filter SharedEnvVariables that belong to a project
   */
  projectId?: string | undefined;
  /**
   * Filter SharedEnvVariables based on comma separated ids
   */
  ids?: string | undefined;
  /**
   * Filter SharedEnvVariables based on comma separated ids
   */
  excludeIdsQueryParameter?: string | undefined;
  /**
   * Filter SharedEnvVariables based on comma separated ids
   */
  excludeIdsQueryParameter1?: string | undefined;
  /**
   * Filter SharedEnvVariables that belong to a project
   */
  excludeProjectIdQueryParameter?: string | undefined;
  /**
   * Filter SharedEnvVariables that belong to a project
   */
  excludeProjectIdQueryParameter1?: 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;
};

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

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

export type ListSharedEnvVariableData = {
  /**
   * 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?: ListSharedEnvVariableType | undefined;
  /**
   * environments this env variable targets
   */
  target?: Array<ListSharedEnvVariableTarget> | 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;
};

export type ListSharedEnvVariableResponseBody = {
  data: Array<ListSharedEnvVariableData>;
  /**
   * This object contains information related to the pagination of the current request, including the necessary parameters to get the next or previous page of data.
   */
  pagination: Pagination;
};

/** @internal */
export type ListSharedEnvVariableRequest$Outbound = {
  search?: string | undefined;
  projectId?: string | undefined;
  ids?: string | undefined;
  exclude_idsQueryParameter?: string | undefined;
  "'exclude-ids'QueryParameter1"?: string | undefined;
  exclude_projectIdQueryParameter?: string | undefined;
  "'exclude-projectId'QueryParameter1"?: string | undefined;
  teamId?: string | undefined;
  slug?: string | undefined;
};

/** @internal */
export const ListSharedEnvVariableRequest$outboundSchema: z.ZodType<
  ListSharedEnvVariableRequest$Outbound,
  z.ZodTypeDef,
  ListSharedEnvVariableRequest
> = z.object({
  search: z.string().optional(),
  projectId: z.string().optional(),
  ids: z.string().optional(),
  excludeIdsQueryParameter: z.string().optional(),
  excludeIdsQueryParameter1: z.string().optional(),
  excludeProjectIdQueryParameter: z.string().optional(),
  excludeProjectIdQueryParameter1: z.string().optional(),
  teamId: z.string().optional(),
  slug: z.string().optional(),
}).transform((v) => {
  return remap$(v, {
    excludeIdsQueryParameter: "exclude_idsQueryParameter",
    excludeIdsQueryParameter1: "'exclude-ids'QueryParameter1",
    excludeProjectIdQueryParameter: "exclude_projectIdQueryParameter",
    excludeProjectIdQueryParameter1: "'exclude-projectId'QueryParameter1",
  });
});

export function listSharedEnvVariableRequestToJSON(
  listSharedEnvVariableRequest: ListSharedEnvVariableRequest,
): string {
  return JSON.stringify(
    ListSharedEnvVariableRequest$outboundSchema.parse(
      listSharedEnvVariableRequest,
    ),
  );
}

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

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

/** @internal */
export const ListSharedEnvVariableData$inboundSchema: z.ZodType<
  ListSharedEnvVariableData,
  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(ListSharedEnvVariableType$inboundSchema),
  target: types.optional(z.array(ListSharedEnvVariableTarget$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 listSharedEnvVariableDataFromJSON(
  jsonString: string,
): SafeParseResult<ListSharedEnvVariableData, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ListSharedEnvVariableData$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ListSharedEnvVariableData' from JSON`,
  );
}

/** @internal */
export const ListSharedEnvVariableResponseBody$inboundSchema: z.ZodType<
  ListSharedEnvVariableResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  data: z.array(z.lazy(() => ListSharedEnvVariableData$inboundSchema)),
  pagination: Pagination$inboundSchema,
});

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