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

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

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

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

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

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

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

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

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

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

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

    return new EnablePaperTrailUnauthorized(remapped);
  });

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

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

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

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

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

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

    return new EnablePaperTrailBadRequest(remapped);
  });

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

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