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

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

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

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

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

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

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

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

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

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

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

    return new GetMetadataChildrenUnauthorized(remapped);
  });

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

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

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

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

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

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

    return new GetMetadataChildrenBadRequest(remapped);
  });

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

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