/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod";
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 {
  List,
  List$inboundSchema,
  List$Outbound,
  List$outboundSchema,
} from "../components/list.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

/**
 * The level of access granted to all members of the workspace for this list. Pass `null` to keep the list private and only grant access to specific workspace members.
 */
export const PatchV2ListsListWorkspaceAccess = {
  FullAccess: "full-access",
  ReadAndWrite: "read-and-write",
  ReadOnly: "read-only",
} as const;
/**
 * The level of access granted to all members of the workspace for this list. Pass `null` to keep the list private and only grant access to specific workspace members.
 */
export type PatchV2ListsListWorkspaceAccess = ClosedEnum<
  typeof PatchV2ListsListWorkspaceAccess
>;

/**
 * The level of access to the list.
 */
export const PatchV2ListsListLevel = {
  FullAccess: "full-access",
  ReadAndWrite: "read-and-write",
  ReadOnly: "read-only",
} as const;
/**
 * The level of access to the list.
 */
export type PatchV2ListsListLevel = ClosedEnum<typeof PatchV2ListsListLevel>;

export type PatchV2ListsListWorkspaceMemberAccess = {
  /**
   * A UUID to identify the workspace member to grant access to.
   */
  workspaceMemberId: string;
  /**
   * The level of access to the list.
   */
  level: PatchV2ListsListLevel;
};

export type PatchV2ListsListData = {
  /**
   * The human-readable name of the list.
   */
  name?: string | undefined;
  /**
   * A unique, human-readable slug to access the list through API calls. Should be formatted in snake case.
   */
  apiSlug?: string | undefined;
  /**
   * The level of access granted to all members of the workspace for this list. Pass `null` to keep the list private and only grant access to specific workspace members.
   */
  workspaceAccess?: PatchV2ListsListWorkspaceAccess | null | undefined;
  /**
   * The level of access granted to specific workspace members for this list. Pass an empty array to grant access to no workspace members.
   */
  workspaceMemberAccess?:
    | Array<PatchV2ListsListWorkspaceMemberAccess>
    | undefined;
};

export type PatchV2ListsListRequestBody = {
  data: PatchV2ListsListData;
};

export type PatchV2ListsListRequest = {
  list: string;
  requestBody: PatchV2ListsListRequestBody;
};

/**
 * Success
 */
export type PatchV2ListsListResponse = {
  data: List;
};

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

/** @internal */
export const PatchV2ListsListWorkspaceAccess$outboundSchema: z.ZodNativeEnum<
  typeof PatchV2ListsListWorkspaceAccess
> = PatchV2ListsListWorkspaceAccess$inboundSchema;

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace PatchV2ListsListWorkspaceAccess$ {
  /** @deprecated use `PatchV2ListsListWorkspaceAccess$inboundSchema` instead. */
  export const inboundSchema = PatchV2ListsListWorkspaceAccess$inboundSchema;
  /** @deprecated use `PatchV2ListsListWorkspaceAccess$outboundSchema` instead. */
  export const outboundSchema = PatchV2ListsListWorkspaceAccess$outboundSchema;
}

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

/** @internal */
export const PatchV2ListsListLevel$outboundSchema: z.ZodNativeEnum<
  typeof PatchV2ListsListLevel
> = PatchV2ListsListLevel$inboundSchema;

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace PatchV2ListsListLevel$ {
  /** @deprecated use `PatchV2ListsListLevel$inboundSchema` instead. */
  export const inboundSchema = PatchV2ListsListLevel$inboundSchema;
  /** @deprecated use `PatchV2ListsListLevel$outboundSchema` instead. */
  export const outboundSchema = PatchV2ListsListLevel$outboundSchema;
}

/** @internal */
export const PatchV2ListsListWorkspaceMemberAccess$inboundSchema: z.ZodType<
  PatchV2ListsListWorkspaceMemberAccess,
  z.ZodTypeDef,
  unknown
> = z.object({
  workspace_member_id: z.string(),
  level: PatchV2ListsListLevel$inboundSchema,
}).transform((v) => {
  return remap$(v, {
    "workspace_member_id": "workspaceMemberId",
  });
});

/** @internal */
export type PatchV2ListsListWorkspaceMemberAccess$Outbound = {
  workspace_member_id: string;
  level: string;
};

/** @internal */
export const PatchV2ListsListWorkspaceMemberAccess$outboundSchema: z.ZodType<
  PatchV2ListsListWorkspaceMemberAccess$Outbound,
  z.ZodTypeDef,
  PatchV2ListsListWorkspaceMemberAccess
> = z.object({
  workspaceMemberId: z.string(),
  level: PatchV2ListsListLevel$outboundSchema,
}).transform((v) => {
  return remap$(v, {
    workspaceMemberId: "workspace_member_id",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace PatchV2ListsListWorkspaceMemberAccess$ {
  /** @deprecated use `PatchV2ListsListWorkspaceMemberAccess$inboundSchema` instead. */
  export const inboundSchema =
    PatchV2ListsListWorkspaceMemberAccess$inboundSchema;
  /** @deprecated use `PatchV2ListsListWorkspaceMemberAccess$outboundSchema` instead. */
  export const outboundSchema =
    PatchV2ListsListWorkspaceMemberAccess$outboundSchema;
  /** @deprecated use `PatchV2ListsListWorkspaceMemberAccess$Outbound` instead. */
  export type Outbound = PatchV2ListsListWorkspaceMemberAccess$Outbound;
}

export function patchV2ListsListWorkspaceMemberAccessToJSON(
  patchV2ListsListWorkspaceMemberAccess: PatchV2ListsListWorkspaceMemberAccess,
): string {
  return JSON.stringify(
    PatchV2ListsListWorkspaceMemberAccess$outboundSchema.parse(
      patchV2ListsListWorkspaceMemberAccess,
    ),
  );
}

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

/** @internal */
export const PatchV2ListsListData$inboundSchema: z.ZodType<
  PatchV2ListsListData,
  z.ZodTypeDef,
  unknown
> = z.object({
  name: z.string().optional(),
  api_slug: z.string().optional(),
  workspace_access: z.nullable(PatchV2ListsListWorkspaceAccess$inboundSchema)
    .optional(),
  workspace_member_access: z.array(
    z.lazy(() => PatchV2ListsListWorkspaceMemberAccess$inboundSchema),
  ).optional(),
}).transform((v) => {
  return remap$(v, {
    "api_slug": "apiSlug",
    "workspace_access": "workspaceAccess",
    "workspace_member_access": "workspaceMemberAccess",
  });
});

/** @internal */
export type PatchV2ListsListData$Outbound = {
  name?: string | undefined;
  api_slug?: string | undefined;
  workspace_access?: string | null | undefined;
  workspace_member_access?:
    | Array<PatchV2ListsListWorkspaceMemberAccess$Outbound>
    | undefined;
};

/** @internal */
export const PatchV2ListsListData$outboundSchema: z.ZodType<
  PatchV2ListsListData$Outbound,
  z.ZodTypeDef,
  PatchV2ListsListData
> = z.object({
  name: z.string().optional(),
  apiSlug: z.string().optional(),
  workspaceAccess: z.nullable(PatchV2ListsListWorkspaceAccess$outboundSchema)
    .optional(),
  workspaceMemberAccess: z.array(
    z.lazy(() => PatchV2ListsListWorkspaceMemberAccess$outboundSchema),
  ).optional(),
}).transform((v) => {
  return remap$(v, {
    apiSlug: "api_slug",
    workspaceAccess: "workspace_access",
    workspaceMemberAccess: "workspace_member_access",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace PatchV2ListsListData$ {
  /** @deprecated use `PatchV2ListsListData$inboundSchema` instead. */
  export const inboundSchema = PatchV2ListsListData$inboundSchema;
  /** @deprecated use `PatchV2ListsListData$outboundSchema` instead. */
  export const outboundSchema = PatchV2ListsListData$outboundSchema;
  /** @deprecated use `PatchV2ListsListData$Outbound` instead. */
  export type Outbound = PatchV2ListsListData$Outbound;
}

export function patchV2ListsListDataToJSON(
  patchV2ListsListData: PatchV2ListsListData,
): string {
  return JSON.stringify(
    PatchV2ListsListData$outboundSchema.parse(patchV2ListsListData),
  );
}

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

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

/** @internal */
export type PatchV2ListsListRequestBody$Outbound = {
  data: PatchV2ListsListData$Outbound;
};

/** @internal */
export const PatchV2ListsListRequestBody$outboundSchema: z.ZodType<
  PatchV2ListsListRequestBody$Outbound,
  z.ZodTypeDef,
  PatchV2ListsListRequestBody
> = z.object({
  data: z.lazy(() => PatchV2ListsListData$outboundSchema),
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace PatchV2ListsListRequestBody$ {
  /** @deprecated use `PatchV2ListsListRequestBody$inboundSchema` instead. */
  export const inboundSchema = PatchV2ListsListRequestBody$inboundSchema;
  /** @deprecated use `PatchV2ListsListRequestBody$outboundSchema` instead. */
  export const outboundSchema = PatchV2ListsListRequestBody$outboundSchema;
  /** @deprecated use `PatchV2ListsListRequestBody$Outbound` instead. */
  export type Outbound = PatchV2ListsListRequestBody$Outbound;
}

export function patchV2ListsListRequestBodyToJSON(
  patchV2ListsListRequestBody: PatchV2ListsListRequestBody,
): string {
  return JSON.stringify(
    PatchV2ListsListRequestBody$outboundSchema.parse(
      patchV2ListsListRequestBody,
    ),
  );
}

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

/** @internal */
export const PatchV2ListsListRequest$inboundSchema: z.ZodType<
  PatchV2ListsListRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  list: z.string(),
  RequestBody: z.lazy(() => PatchV2ListsListRequestBody$inboundSchema),
}).transform((v) => {
  return remap$(v, {
    "RequestBody": "requestBody",
  });
});

/** @internal */
export type PatchV2ListsListRequest$Outbound = {
  list: string;
  RequestBody: PatchV2ListsListRequestBody$Outbound;
};

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

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace PatchV2ListsListRequest$ {
  /** @deprecated use `PatchV2ListsListRequest$inboundSchema` instead. */
  export const inboundSchema = PatchV2ListsListRequest$inboundSchema;
  /** @deprecated use `PatchV2ListsListRequest$outboundSchema` instead. */
  export const outboundSchema = PatchV2ListsListRequest$outboundSchema;
  /** @deprecated use `PatchV2ListsListRequest$Outbound` instead. */
  export type Outbound = PatchV2ListsListRequest$Outbound;
}

export function patchV2ListsListRequestToJSON(
  patchV2ListsListRequest: PatchV2ListsListRequest,
): string {
  return JSON.stringify(
    PatchV2ListsListRequest$outboundSchema.parse(patchV2ListsListRequest),
  );
}

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

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

/** @internal */
export type PatchV2ListsListResponse$Outbound = {
  data: List$Outbound;
};

/** @internal */
export const PatchV2ListsListResponse$outboundSchema: z.ZodType<
  PatchV2ListsListResponse$Outbound,
  z.ZodTypeDef,
  PatchV2ListsListResponse
> = z.object({
  data: List$outboundSchema,
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace PatchV2ListsListResponse$ {
  /** @deprecated use `PatchV2ListsListResponse$inboundSchema` instead. */
  export const inboundSchema = PatchV2ListsListResponse$inboundSchema;
  /** @deprecated use `PatchV2ListsListResponse$outboundSchema` instead. */
  export const outboundSchema = PatchV2ListsListResponse$outboundSchema;
  /** @deprecated use `PatchV2ListsListResponse$Outbound` instead. */
  export type Outbound = PatchV2ListsListResponse$Outbound;
}

export function patchV2ListsListResponseToJSON(
  patchV2ListsListResponse: PatchV2ListsListResponse,
): string {
  return JSON.stringify(
    PatchV2ListsListResponse$outboundSchema.parse(patchV2ListsListResponse),
  );
}

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