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

import * as z from "zod";
import { remap as remap$ } from "../../../lib/primitives.js";

export type AddPlaylistContentsPlaylistsErrors = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/**
 * Unauthorized - Returned if the X-Plex-Token is missing from the header or query.
 */
export type AddPlaylistContentsUnauthorizedData = {
  errors?: Array<AddPlaylistContentsPlaylistsErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;
};

/**
 * Unauthorized - Returned if the X-Plex-Token is missing from the header or query.
 */
export class AddPlaylistContentsUnauthorized extends Error {
  errors?: Array<AddPlaylistContentsPlaylistsErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

  /** The original data that was passed to this error instance. */
  data$: AddPlaylistContentsUnauthorizedData;

  constructor(err: AddPlaylistContentsUnauthorizedData) {
    const message = "message" in err && typeof err.message === "string"
      ? err.message
      : `API error occurred: ${JSON.stringify(err)}`;
    super(message);
    this.data$ = err;

    if (err.errors != null) this.errors = err.errors;
    if (err.rawResponse != null) this.rawResponse = err.rawResponse;

    this.name = "AddPlaylistContentsUnauthorized";
  }
}

export type AddPlaylistContentsErrors = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/**
 * Bad Request - A parameter was not specified, or was specified incorrectly.
 */
export type AddPlaylistContentsBadRequestData = {
  errors?: Array<AddPlaylistContentsErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;
};

/**
 * Bad Request - A parameter was not specified, or was specified incorrectly.
 */
export class AddPlaylistContentsBadRequest extends Error {
  errors?: Array<AddPlaylistContentsErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

  /** The original data that was passed to this error instance. */
  data$: AddPlaylistContentsBadRequestData;

  constructor(err: AddPlaylistContentsBadRequestData) {
    const message = "message" in err && typeof err.message === "string"
      ? err.message
      : `API error occurred: ${JSON.stringify(err)}`;
    super(message);
    this.data$ = err;

    if (err.errors != null) this.errors = err.errors;
    if (err.rawResponse != null) this.rawResponse = err.rawResponse;

    this.name = "AddPlaylistContentsBadRequest";
  }
}

/** @internal */
export const AddPlaylistContentsPlaylistsErrors$inboundSchema: z.ZodType<
  AddPlaylistContentsPlaylistsErrors,
  z.ZodTypeDef,
  unknown
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

/** @internal */
export type AddPlaylistContentsPlaylistsErrors$Outbound = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/** @internal */
export const AddPlaylistContentsPlaylistsErrors$outboundSchema: z.ZodType<
  AddPlaylistContentsPlaylistsErrors$Outbound,
  z.ZodTypeDef,
  AddPlaylistContentsPlaylistsErrors
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

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

/** @internal */
export const AddPlaylistContentsUnauthorized$inboundSchema: z.ZodType<
  AddPlaylistContentsUnauthorized,
  z.ZodTypeDef,
  unknown
> = z.object({
  errors: z.array(
    z.lazy(() => AddPlaylistContentsPlaylistsErrors$inboundSchema),
  ).optional(),
  RawResponse: z.instanceof(Response).optional(),
})
  .transform((v) => {
    const remapped = remap$(v, {
      "RawResponse": "rawResponse",
    });

    return new AddPlaylistContentsUnauthorized(remapped);
  });

/** @internal */
export type AddPlaylistContentsUnauthorized$Outbound = {
  errors?: Array<AddPlaylistContentsPlaylistsErrors$Outbound> | undefined;
  RawResponse?: never | undefined;
};

/** @internal */
export const AddPlaylistContentsUnauthorized$outboundSchema: z.ZodType<
  AddPlaylistContentsUnauthorized$Outbound,
  z.ZodTypeDef,
  AddPlaylistContentsUnauthorized
> = z.instanceof(AddPlaylistContentsUnauthorized)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(
        z.lazy(() => AddPlaylistContentsPlaylistsErrors$outboundSchema),
      ).optional(),
      rawResponse: z.instanceof(Response).transform(() => {
        throw new Error("Response cannot be serialized");
      }).optional(),
    }).transform((v) => {
      return remap$(v, {
        rawResponse: "RawResponse",
      });
    }),
  );

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

/** @internal */
export const AddPlaylistContentsErrors$inboundSchema: z.ZodType<
  AddPlaylistContentsErrors,
  z.ZodTypeDef,
  unknown
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

/** @internal */
export type AddPlaylistContentsErrors$Outbound = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/** @internal */
export const AddPlaylistContentsErrors$outboundSchema: z.ZodType<
  AddPlaylistContentsErrors$Outbound,
  z.ZodTypeDef,
  AddPlaylistContentsErrors
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

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

/** @internal */
export const AddPlaylistContentsBadRequest$inboundSchema: z.ZodType<
  AddPlaylistContentsBadRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  errors: z.array(z.lazy(() => AddPlaylistContentsErrors$inboundSchema))
    .optional(),
  RawResponse: z.instanceof(Response).optional(),
})
  .transform((v) => {
    const remapped = remap$(v, {
      "RawResponse": "rawResponse",
    });

    return new AddPlaylistContentsBadRequest(remapped);
  });

/** @internal */
export type AddPlaylistContentsBadRequest$Outbound = {
  errors?: Array<AddPlaylistContentsErrors$Outbound> | undefined;
  RawResponse?: never | undefined;
};

/** @internal */
export const AddPlaylistContentsBadRequest$outboundSchema: z.ZodType<
  AddPlaylistContentsBadRequest$Outbound,
  z.ZodTypeDef,
  AddPlaylistContentsBadRequest
> = z.instanceof(AddPlaylistContentsBadRequest)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(z.lazy(() => AddPlaylistContentsErrors$outboundSchema))
        .optional(),
      rawResponse: z.instanceof(Response).transform(() => {
        throw new Error("Response cannot be serialized");
      }).optional(),
    }).transform((v) => {
      return remap$(v, {
        rawResponse: "RawResponse",
      });
    }),
  );

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