/*
 * 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 PostV2ListsWorkspaceAccess = {
  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 PostV2ListsWorkspaceAccess = ClosedEnum<
  typeof PostV2ListsWorkspaceAccess
>;

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

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

export type PostV2ListsData = {
  /**
   * The human-readable name of the list.
   */
  name: string;
  /**
   * A unique, human-readable slug to access the list through API calls. Should be formatted in snake case.
   */
  apiSlug: string;
  /**
   * A UUID or slug to identify the allowed object type for records added to this list.
   */
  parentObject: string;
  /**
   * 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: PostV2ListsWorkspaceAccess | null;
  /**
   * 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<PostV2ListsWorkspaceMemberAccess>;
};

export type PostV2ListsRequest = {
  data: PostV2ListsData;
};

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

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

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

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

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

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

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

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

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

/** @internal */
export const PostV2ListsWorkspaceMemberAccess$outboundSchema: z.ZodType<
  PostV2ListsWorkspaceMemberAccess$Outbound,
  z.ZodTypeDef,
  PostV2ListsWorkspaceMemberAccess
> = z.object({
  workspaceMemberId: z.string(),
  level: PostV2ListsLevel$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 PostV2ListsWorkspaceMemberAccess$ {
  /** @deprecated use `PostV2ListsWorkspaceMemberAccess$inboundSchema` instead. */
  export const inboundSchema = PostV2ListsWorkspaceMemberAccess$inboundSchema;
  /** @deprecated use `PostV2ListsWorkspaceMemberAccess$outboundSchema` instead. */
  export const outboundSchema = PostV2ListsWorkspaceMemberAccess$outboundSchema;
  /** @deprecated use `PostV2ListsWorkspaceMemberAccess$Outbound` instead. */
  export type Outbound = PostV2ListsWorkspaceMemberAccess$Outbound;
}

export function postV2ListsWorkspaceMemberAccessToJSON(
  postV2ListsWorkspaceMemberAccess: PostV2ListsWorkspaceMemberAccess,
): string {
  return JSON.stringify(
    PostV2ListsWorkspaceMemberAccess$outboundSchema.parse(
      postV2ListsWorkspaceMemberAccess,
    ),
  );
}

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

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

/** @internal */
export type PostV2ListsData$Outbound = {
  name: string;
  api_slug: string;
  parent_object: string;
  workspace_access: string | null;
  workspace_member_access: Array<PostV2ListsWorkspaceMemberAccess$Outbound>;
};

/** @internal */
export const PostV2ListsData$outboundSchema: z.ZodType<
  PostV2ListsData$Outbound,
  z.ZodTypeDef,
  PostV2ListsData
> = z.object({
  name: z.string(),
  apiSlug: z.string(),
  parentObject: z.string(),
  workspaceAccess: z.nullable(PostV2ListsWorkspaceAccess$outboundSchema),
  workspaceMemberAccess: z.array(
    z.lazy(() => PostV2ListsWorkspaceMemberAccess$outboundSchema),
  ),
}).transform((v) => {
  return remap$(v, {
    apiSlug: "api_slug",
    parentObject: "parent_object",
    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 PostV2ListsData$ {
  /** @deprecated use `PostV2ListsData$inboundSchema` instead. */
  export const inboundSchema = PostV2ListsData$inboundSchema;
  /** @deprecated use `PostV2ListsData$outboundSchema` instead. */
  export const outboundSchema = PostV2ListsData$outboundSchema;
  /** @deprecated use `PostV2ListsData$Outbound` instead. */
  export type Outbound = PostV2ListsData$Outbound;
}

export function postV2ListsDataToJSON(
  postV2ListsData: PostV2ListsData,
): string {
  return JSON.stringify(PostV2ListsData$outboundSchema.parse(postV2ListsData));
}

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

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

/** @internal */
export type PostV2ListsRequest$Outbound = {
  data: PostV2ListsData$Outbound;
};

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

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

export function postV2ListsRequestToJSON(
  postV2ListsRequest: PostV2ListsRequest,
): string {
  return JSON.stringify(
    PostV2ListsRequest$outboundSchema.parse(postV2ListsRequest),
  );
}

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

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

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

/** @internal */
export const PostV2ListsResponse$outboundSchema: z.ZodType<
  PostV2ListsResponse$Outbound,
  z.ZodTypeDef,
  PostV2ListsResponse
> = 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 PostV2ListsResponse$ {
  /** @deprecated use `PostV2ListsResponse$inboundSchema` instead. */
  export const inboundSchema = PostV2ListsResponse$inboundSchema;
  /** @deprecated use `PostV2ListsResponse$outboundSchema` instead. */
  export const outboundSchema = PostV2ListsResponse$outboundSchema;
  /** @deprecated use `PostV2ListsResponse$Outbound` instead. */
  export type Outbound = PostV2ListsResponse$Outbound;
}

export function postV2ListsResponseToJSON(
  postV2ListsResponse: PostV2ListsResponse,
): string {
  return JSON.stringify(
    PostV2ListsResponse$outboundSchema.parse(postV2ListsResponse),
  );
}

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