/*
 * 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 GetPlaylistsPlaylistsErrors = {
  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 GetPlaylistsUnauthorizedData = {
  errors?: Array<GetPlaylistsPlaylistsErrors> | 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 GetPlaylistsUnauthorized extends Error {
  errors?: Array<GetPlaylistsPlaylistsErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

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

  constructor(err: GetPlaylistsUnauthorizedData) {
    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 = "GetPlaylistsUnauthorized";
  }
}

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

/**
 * Bad Request - A parameter was not specified, or was specified incorrectly.
 */
export type GetPlaylistsBadRequestData = {
  errors?: Array<GetPlaylistsErrors> | 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 GetPlaylistsBadRequest extends Error {
  errors?: Array<GetPlaylistsErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

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

  constructor(err: GetPlaylistsBadRequestData) {
    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 = "GetPlaylistsBadRequest";
  }
}

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

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

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

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

    return new GetPlaylistsUnauthorized(remapped);
  });

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

/** @internal */
export const GetPlaylistsUnauthorized$outboundSchema: z.ZodType<
  GetPlaylistsUnauthorized$Outbound,
  z.ZodTypeDef,
  GetPlaylistsUnauthorized
> = z.instanceof(GetPlaylistsUnauthorized)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(z.lazy(() => GetPlaylistsPlaylistsErrors$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 GetPlaylistsUnauthorized$ {
  /** @deprecated use `GetPlaylistsUnauthorized$inboundSchema` instead. */
  export const inboundSchema = GetPlaylistsUnauthorized$inboundSchema;
  /** @deprecated use `GetPlaylistsUnauthorized$outboundSchema` instead. */
  export const outboundSchema = GetPlaylistsUnauthorized$outboundSchema;
  /** @deprecated use `GetPlaylistsUnauthorized$Outbound` instead. */
  export type Outbound = GetPlaylistsUnauthorized$Outbound;
}

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

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

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

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

    return new GetPlaylistsBadRequest(remapped);
  });

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

/** @internal */
export const GetPlaylistsBadRequest$outboundSchema: z.ZodType<
  GetPlaylistsBadRequest$Outbound,
  z.ZodTypeDef,
  GetPlaylistsBadRequest
> = z.instanceof(GetPlaylistsBadRequest)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(z.lazy(() => GetPlaylistsErrors$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 GetPlaylistsBadRequest$ {
  /** @deprecated use `GetPlaylistsBadRequest$inboundSchema` instead. */
  export const inboundSchema = GetPlaylistsBadRequest$inboundSchema;
  /** @deprecated use `GetPlaylistsBadRequest$outboundSchema` instead. */
  export const outboundSchema = GetPlaylistsBadRequest$outboundSchema;
  /** @deprecated use `GetPlaylistsBadRequest$Outbound` instead. */
  export type Outbound = GetPlaylistsBadRequest$Outbound;
}
