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

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

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

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

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

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

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

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

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

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

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

    return new StartUniversalTranscodeUnauthorized(remapped);
  });

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

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

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

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

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

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

    return new StartUniversalTranscodeBadRequest(remapped);
  });

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

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