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

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

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

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

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

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

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

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

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

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

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

    return new GetCompanionsDataUnauthorized(remapped);
  });

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

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

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

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

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

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

    return new GetCompanionsDataBadRequest(remapped);
  });

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

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